-
Notifications
You must be signed in to change notification settings - Fork 26.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
creating a new Request from an existing object does not keep the request's method #36522
Closed
1 task done
Labels
Middleware
Related to Next.js Middleware.
Comments
8 tasks
balazsorban44
added
Middleware
Related to Next.js Middleware.
kind: bug
and removed
bug
Issue was opened via the bug report template.
labels
Apr 28, 2022
@gazs @balazsorban44 We are experiencing this as well (case 2 in OP). A simple repro we have in a import { NextResponse } from 'next/server';
export default async function () {
const ok = await fetch('https://httpbin.org/post', {
method: 'POST',
body: 'test',
});
console.log(ok); // <-- 200 OK
const fails = await fetch(
new Request('https://httpbin.org/post', {
method: 'POST',
body: 'test',
})
);
console.log(fails); // <-- 405 METHOD NOT ALLOWED (GET is sent)
return NextResponse.next();
} |
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Verify canary release
Provide environment information
What browser are you using? (if relevant)
n/a
How are you deploying your application? (if relevant)
n/a
Describe the Bug
throws:
TypeError: Request with GET/HEAD method cannot have body
this is because the polyfill takes method from the optional
init
parameter of Request#constructor:next.js/packages/next/server/web/spec-compliant/request.ts
Lines 19 to 26 in 842e4ec
next.js/packages/next/server/web/sandbox/context.ts
Lines 152 to 173 in d5e767b
Expected Behavior
the expected behaviour is the
method
and any other properties are copied over to the new request objectTo Reproduce
for example in _middleware.ts:
The text was updated successfully, but these errors were encountered: