Skip to content

Fetch: fixed handling of Content-Length header when body is provided. #933

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

Merged
merged 1 commit into from
Jun 18, 2025

Conversation

xeioex
Copy link
Contributor

@xeioex xeioex commented Jun 17, 2025

body value length takes precedence over Content-Length from header list.

https://fetch.spec.whatwg.org/#http-network-or-cache-fetch

Let contentLength be httpRequest’s body’s length, if httpRequest’s body

is non-null; otherwise null.

Let contentLengthHeaderValue be null.

If httpRequest’s body is null and httpRequest’s method is `POST` or

PUT, then set contentLengthHeaderValue to 0.

If contentLength is non-null, then set contentLengthHeaderValue to

contentLength, serialized and isomorphic encoded.

If contentLengthHeaderValue is non-null, then append (`Content-Length`,

contentLengthHeaderValue) to httpRequest’s header list.

This fixes #930 issue in Github.

body value length takes precedence over Content-Length from header list.

    https://fetch.spec.whatwg.org/#http-network-or-cache-fetch

    Let contentLength be httpRequest’s body’s length, if httpRequest’s body
is non-null; otherwise null.

    Let contentLengthHeaderValue be null.

    If httpRequest’s body is null and httpRequest’s method is `POST` or
`PUT`, then set contentLengthHeaderValue to `0`.

    If contentLength is non-null, then set contentLengthHeaderValue to
contentLength, serialized and isomorphic encoded.

    If contentLengthHeaderValue is non-null, then append (`Content-Length`,
contentLengthHeaderValue) to httpRequest’s header list.

This fixes nginx#930 issue in Github.
Copy link
Contributor

@VadimZhestikov VadimZhestikov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

@xeioex xeioex merged commit 34b8051 into nginx:master Jun 18, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Strange error 400 from ngx.fetch with body
2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy