export interface SizedRequestBodyValue { size: number; } export function parsedRequestBodySize( request: Request, values: Array, ): number { const contentLength = request.headers.get("content-length"); if (contentLength && /^\d+$/.test(contentLength)) { return Number(contentLength); } // Content-Length is present for normal browser multipart submissions. The // fallback still enforces the configured limit for chunked/custom clients, // excluding only multipart framing that is no longer available after Astro // has parsed the action input. return values.reduce( (size, value) => size + (typeof value === "string" ? new TextEncoder().encode(value).byteLength : value.size), 0, ); }