Skip to content

Commit

Permalink
keep method when cloning Request, fixes #36522 (#36539)
Browse files Browse the repository at this point in the history
keep method when cloning Request

Co-authored-by: JJ Kasper <jj@jjsweb.site>
  • Loading branch information
gazs and ijjk committed May 22, 2022
1 parent 3bd42b4 commit 863db9b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/next/server/web/spec-compliant/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ class BaseRequest extends Body implements Request {
}

constructor(input: BaseRequest | string, init: RequestInit = {}) {
const method = init.method?.toUpperCase() ?? 'GET'
const method =
init.method?.toUpperCase() ??
(input instanceof BaseRequest ? input.method?.toUpperCase() : 'GET')

if (
(method === 'GET' || method === 'HEAD') &&
Expand Down
11 changes: 11 additions & 0 deletions test/unit/web-runtime/request.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,14 @@ it('Request.referrer can be customized', async () => {
const request = new Request('https://vercel.com', { referrer: 'client' })
expect(request.referrer).toBe('client')
})

it('Request copies over method', async () => {
const request = new Request('https://vercel.com', {
method: 'POST',
body: 'hello',
})

const clonedRequest = new Request(request)

expect(clonedRequest.method).toBe(request.method)
})

0 comments on commit 863db9b

Please sign in to comment.