-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix plugin structure and BetterHttpInstrumentation
- Loading branch information
Showing
9 changed files
with
95 additions
and
55 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { ClientRequest } from "http"; | ||
|
||
export function captureBody(request: ClientRequest): Promise<string> { | ||
return new Promise((resolve, reject) => { | ||
const chunks: string[] = []; | ||
const oldWrite = request.write.bind(request); | ||
const oldEnd = request.end.bind(request); | ||
request.on('data', chunk => { | ||
chunks.push(decodeURIComponent(chunk.toString())) | ||
return oldWrite(chunk); | ||
}); | ||
request.on('end', (chunk) => { | ||
if (chunk) { | ||
chunks.push(decodeURIComponent(chunk.toString())); | ||
} | ||
oldEnd(chunk); | ||
return resolve(chunks.join('')) | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,18 @@ | ||
import { ClientRequest, IncomingHttpHeaders, IncomingMessage, ServerResponse } from "http"; | ||
import { ClientRequest, IncomingMessage, ServerResponse } from "http"; | ||
|
||
export type Plugin = { | ||
shouldParseRequest?(request: ClientRequest | IncomingMessage): boolean; | ||
shouldParseResponse?(response: IncomingMessage | ServerResponse<IncomingMessage>): boolean; | ||
export class HttpPlugin { | ||
parseIncommingMessage?(request: IncomingMessage): Record<string, unknown>; | ||
parseClientRequest?(request: ClientRequest): Record<string, unknown>; | ||
captureBody?: boolean; | ||
name: string; | ||
} | ||
captureBody = false | ||
name = 'base-plugin-should-extend' | ||
constructor() { | ||
|
||
} | ||
|
||
shouldParseRequest(request: ClientRequest | IncomingMessage): boolean { | ||
return false; | ||
} | ||
shouldParseResponse(response: IncomingMessage | ServerResponse<IncomingMessage>): boolean { | ||
return false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
export { BaselimeSDK } from './baselime.ts'; | ||
export { tracing as trpcTracingMiddleware } from './trpc.ts'; | ||
export { betterHttpInstrumentation } from './http.ts'; | ||
export { BetterHttpInstrumentation } from './http.ts'; | ||
export { StripePlugin } from './http-plugins/stripe.ts'; | ||
export { Plugin } from './http-plugins/plugin.ts'; | ||
export { HttpPlugin } from './http-plugins/plugin.ts'; | ||
export { VercelPlugin } from './http-plugins/vercel.ts'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters