-
-
Notifications
You must be signed in to change notification settings - Fork 514
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
fix(openapi-fetch): prevent body parsing for HEAD requests regardless of Content-Length #2205
Conversation
… of Content-Length
👷 Deploy request for openapi-ts pending review.Visit the deploys page to approve it
|
🦋 Changeset detectedLatest commit: dabe0b5 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me. Just add a patch
changeset (see GitHub comment) so we can create a release from this PR
@@ -13,4 +13,16 @@ describe("HEAD", () => { | |||
await client.HEAD("/resources/{id}", { params: { path: { id: 123 } } }); | |||
expect(method).toBe("HEAD"); | |||
}); | |||
|
|||
test("handles HEAD requests with non-zero Content-Length without parsing the body", async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great test!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, thank you!
Changes
This PR fixes how HEAD method requests are handled in openapi-fetch by preventing body parsing regardless of the Content-Length header value.
According to RFC 9110, HEAD responses should have the same metadata as GET but must not include a body.
Previously, the library only handled this correctly when Content-Length was "0", causing JSON parsing errors in other cases.
Fixes HEAD method with non-zero Content-Length triggers JSON parsing error #2195.
How to Review
Checklist
docs/
updated (if necessary) - N/Apnpm run update:examples
run (only applicable for openapi-typescript) - N/A