Skip to content

Commit

Permalink
Include message body in redirect responses (#25257)
Browse files Browse the repository at this point in the history
### Description
The redirect responses from the redirect function do not contain a message body. This is in conflict with the RFCs below and causes Traefik (a reverse proxy) to invalidate the responses. In this pull request, I add a response body to the redirect responses.

### References
- https://datatracker.ietf.org/doc/html/rfc7230#section-3.3
> All 1xx (Informational), 204 (No Content), and 304 (Not Modified) responses must not include a message-body. All other responses do include a message-body, although the body may be of zero length.

- https://datatracker.ietf.org/doc/html/rfc7231#section-6.4.3
> The server's response payload usually contains a short hypertext note with a hyperlink to the different URI(s).

- traefik/traefik#4456
- auth0/nextjs-auth0#399
  • Loading branch information
michielvangendt authored Jul 9, 2021
1 parent 7c56684 commit d22ecd9
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/next/server/api-utils.ts
Original file line number Diff line number Diff line change
@@ -237,7 +237,7 @@ export function redirect(
)
}
res.writeHead(statusOrUrl, { Location: url })
res.write('')
res.write(url)
res.end()
return res
}
4 changes: 4 additions & 0 deletions test/integration/api-support/test/index.test.js
Original file line number Diff line number Diff line change
@@ -262,6 +262,8 @@ function runTests(dev = false) {
})

expect(res.status).toEqual(307)
const text = await res.text()
expect(text).toEqual('/login')
})

it('should redirect to login', async () => {
@@ -277,6 +279,8 @@ function runTests(dev = false) {
})

expect(res.status).toEqual(301)
const text = await res.text()
expect(text).toEqual('/login')
})

it('should return empty query object', async () => {

0 comments on commit d22ecd9

Please sign in to comment.