@@ -323,9 +323,10 @@ export function getActionContext(context: APIContext): AstroActionContext {
323323 throw error ;
324324 }
325325
326+ const bodySizeLimit = pipeline . manifest . actionBodySizeLimit ;
326327 let input ;
327328 try {
328- input = await parseRequestBody ( context . request ) ;
329+ input = await parseRequestBody ( context . request , bodySizeLimit ) ;
329330 } catch ( e ) {
330331 if ( e instanceof ActionError ) {
331332 return { data : undefined , error : e } ;
@@ -381,24 +382,22 @@ function getCallerInfo(ctx: APIContext) {
381382 return undefined ;
382383}
383384
384- const DEFAULT_ACTION_BODY_SIZE_LIMIT = 1024 * 1024 ;
385-
386- async function parseRequestBody ( request : Request ) {
385+ async function parseRequestBody ( request : Request , bodySizeLimit : number ) {
387386 const contentType = request . headers . get ( 'content-type' ) ;
388387 const contentLengthHeader = request . headers . get ( 'content-length' ) ;
389388 const contentLength = contentLengthHeader ? Number . parseInt ( contentLengthHeader , 10 ) : undefined ;
390389 const hasContentLength = typeof contentLength === 'number' && Number . isFinite ( contentLength ) ;
391390
392391 if ( ! contentType ) return undefined ;
393- if ( hasContentLength && contentLength > DEFAULT_ACTION_BODY_SIZE_LIMIT ) {
392+ if ( hasContentLength && contentLength > bodySizeLimit ) {
394393 throw new ActionError ( {
395394 code : 'CONTENT_TOO_LARGE' ,
396- message : `Request body exceeds ${ DEFAULT_ACTION_BODY_SIZE_LIMIT } bytes` ,
395+ message : `Request body exceeds ${ bodySizeLimit } bytes` ,
397396 } ) ;
398397 }
399398 if ( hasContentType ( contentType , formContentTypes ) ) {
400399 if ( ! hasContentLength ) {
401- const body = await readRequestBodyWithLimit ( request . clone ( ) , DEFAULT_ACTION_BODY_SIZE_LIMIT ) ;
400+ const body = await readRequestBodyWithLimit ( request . clone ( ) , bodySizeLimit ) ;
402401 const formRequest = new Request ( request . url , {
403402 method : request . method ,
404403 headers : request . headers ,
@@ -411,7 +410,7 @@ async function parseRequestBody(request: Request) {
411410 if ( hasContentType ( contentType , [ 'application/json' ] ) ) {
412411 if ( contentLength === 0 ) return undefined ;
413412 if ( ! hasContentLength ) {
414- const body = await readRequestBodyWithLimit ( request . clone ( ) , DEFAULT_ACTION_BODY_SIZE_LIMIT ) ;
413+ const body = await readRequestBodyWithLimit ( request . clone ( ) , bodySizeLimit ) ;
415414 if ( body . byteLength === 0 ) return undefined ;
416415 return JSON . parse ( new TextDecoder ( ) . decode ( body ) ) ;
417416 }
0 commit comments