Skip to content
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

Exclude body req for GET/HEAD according to fetch api #1050

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/hono/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,13 @@ function convertToStandardRequest(req: HonoRequest): Request {
headers[key] = value;
}

// https://developer.mozilla.org/en-US/docs/Web/API/fetch#body
const includeBody = ["GET", "HEAD"].includes(req.raw.method);

return new Request(req.raw.url, {
method: req.raw.method,
headers,
body: req.raw.body,
body: includeBody ? req.raw.body : undefined,
// @ts-ignore
duplex: "half",
});
Expand Down
5 changes: 4 additions & 1 deletion packages/nextjs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,15 @@ async function convertToStandardRequest(nextReq: NextApiRequest): Promise<Reques
headers.set(key, value as string);
});

// https://developer.mozilla.org/en-US/docs/Web/API/fetch#body
const includeBody = !!method && ["GET", "HEAD"].includes(method);

// Create a new Request object (hardcode the url because it doesn't really matter what it is)
const webReq = new Request("https://next.js/api/trigger", {
headers,
method,
// @ts-ignore
body: nextReq,
body: includeBody ? nextReq : undefined,
duplex: "half",
});

Expand Down