* Bound the unauthenticated AgentMail webhook body before buffering it for Svix * signature verification, so an oversized payload cannot exhaust pod memory.
(req: Request)
| 44 | * signature verification, so an oversized payload cannot exhaust pod memory. |
| 45 | */ |
| 46 | async function readAgentMailBody(req: Request): Promise<string> { |
| 47 | assertContentLengthWithinLimit(req.headers, WEBHOOK_MAX_BODY_BYTES, AGENTMAIL_BODY_LABEL) |
| 48 | const buffer = await readStreamToBufferWithLimit(req.body, { |
| 49 | maxBytes: WEBHOOK_MAX_BODY_BYTES, |
| 50 | label: AGENTMAIL_BODY_LABEL, |
| 51 | }) |
| 52 | return new TextDecoder().decode(buffer) |
| 53 | } |
| 54 | |
| 55 | export const POST = withRouteHandler(async (req: Request) => { |
| 56 | try { |
no test coverage detected