Skip to content
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.

Commit

Permalink
5MB -> 4MB body size limit (vercel#26887)
Browse files Browse the repository at this point in the history
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: vercel#26831
  • Loading branch information
padmaia authored Jul 2, 2021
1 parent ca2879f commit 718342e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions errors/api-routes-body-size-limit.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# API Routes Body Size Limited to 5mb
# API Routes Body Size Limited to 4MB

#### 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

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

Expand Down
4 changes: 2 additions & 2 deletions packages/next/server/api-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ export async function apiResolver(
contentLength += Buffer.byteLength(args[0])
}

if (contentLength >= 5 * 1024 * 1024) {
if (contentLength >= 4 * 1024 * 1024) {
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`
)
}

Expand Down
6 changes: 3 additions & 3 deletions test/integration/api-support/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -398,17 +398,17 @@ function runTests(dev = false) {
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')
expect(res.ok).toBeTruthy()
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')
expect(res.ok).toBeTruthy()
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.'
)
})

Expand Down

0 comments on commit 718342e

Please sign in to comment.