import{MAX_REQUEST_BODY_SIZE_MB as i}from"../constants.js";import{RequestBodySizeLimitError as t}from"../errors.js";import{readStreamWithSizeLimit as o}from"./read-stream-with-size-limit.js";async function d(e){return e?o({stream:e,maxSizeMB:i,onSizeExceededErrorHandler:()=>{throw new t(`Request body size exceeded limit of ${i} MB.`)}}):null}function n(e){return Object.fromEntries(e.entries())}async function f(e){const r=await d(e.body);return{method:e.method,url:e.url,headers:n(e.headers),body:Buffer.isBuffer(r)?r.toString():r,bodyUsed:e.bodyUsed,cache:e.cache,credentials:e.credentials,destination:e.destination,integrity:e.integrity,mode:e.mode,redirect:e.redirect,referrer:e.referrer,referrerPolicy:e.referrerPolicy}}export{f as serializeRequest};
