Unverified Commit b8f3a6d2 authored by Maia Teegarden's avatar Maia Teegarden Committed by GitHub

5MB -> 4MB body size limit (#26887)

This decreases the body size limit that triggers a warning from 5MB -> 4MB, which provides a little more wiggle room. Certain things like using base64 on body, headers, path, etc can cause the response to be larger than initially calculated. 

Initial PR: https://github.com/vercel/next.js/pull/26831
parent b4089998
# API Routes Body Size Limited to 5mb # API Routes Body Size Limited to 4MB
#### Why This Error Occurred #### Why This Error Occurred
API Routes are meant to respond quickly and are not intended to support responding with large amounts of data. The maximum size of responses is 5 MB. API Routes are meant to respond quickly and are not intended to support responding with large amounts of data. The maximum size of responses is 4 MB.
#### Possible Ways to Fix It #### Possible Ways to Fix It
Limit your API Route responses to less than 5 MB. If you need to support sending large files to the client, you should consider using a dedicated media host for those assets. See link below for suggestions. Limit your API Route responses to less than 4 MB. If you need to support sending large files to the client, you should consider using a dedicated media host for those assets. See link below for suggestions.
### Useful Links ### Useful Links
......
...@@ -75,9 +75,9 @@ export async function apiResolver( ...@@ -75,9 +75,9 @@ export async function apiResolver(
contentLength += Buffer.byteLength(args[0]) contentLength += Buffer.byteLength(args[0])
} }
if (contentLength >= 5 * 1024 * 1024) { if (contentLength >= 4 * 1024 * 1024) {
console.warn( console.warn(
`API response for ${req.url} exceeds 5MB. This will cause the request to fail in a future version. https://nextjs.org/docs/messages/api-routes-body-size-limit` `API response for ${req.url} exceeds 4MB. This will cause the request to fail in a future version. https://nextjs.org/docs/messages/api-routes-body-size-limit`
) )
} }
......
...@@ -398,17 +398,17 @@ function runTests(dev = false) { ...@@ -398,17 +398,17 @@ function runTests(dev = false) {
expect(data).toBe('hi') expect(data).toBe('hi')
}) })
it('should warn if response body is larger than 5MB', async () => { it('should warn if response body is larger than 4MB', async () => {
let res = await fetchViaHTTP(appPort, '/api/large-response') let res = await fetchViaHTTP(appPort, '/api/large-response')
expect(res.ok).toBeTruthy() expect(res.ok).toBeTruthy()
expect(stderr).toContain( expect(stderr).toContain(
'API response for /api/large-response exceeds 5MB. This will cause the request to fail in a future version.' 'API response for /api/large-response exceeds 4MB. This will cause the request to fail in a future version.'
) )
res = await fetchViaHTTP(appPort, '/api/large-chunked-response') res = await fetchViaHTTP(appPort, '/api/large-chunked-response')
expect(res.ok).toBeTruthy() expect(res.ok).toBeTruthy()
expect(stderr).toContain( expect(stderr).toContain(
'API response for /api/large-chunked-response exceeds 5MB. This will cause the request to fail in a future version.' 'API response for /api/large-chunked-response exceeds 4MB. This will cause the request to fail in a future version.'
) )
}) })
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment