]> git.kaiwu.me - njs.git/commit
Fetch: fixed handling of Content-Length header when body is provided.
authorDmitry Volyntsev <xeioex@nginx.com>
Tue, 17 Jun 2025 02:36:35 +0000 (19:36 -0700)
committerDmitry Volyntsev <xeioexception@gmail.com>
Wed, 18 Jun 2025 21:11:57 +0000 (14:11 -0700)
commit34b80511acfd44a5cbbbce835d7540081e5d7527
treea865826094de6263bd69ee53f504780dc452e6b8
parentc5b1d59fe0a18a77b6a4a3fd9f93ad2b4d497225
Fetch: fixed handling of Content-Length header when body is provided.

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.
nginx/ngx_js_fetch.c
nginx/ngx_qjs_fetch.c
nginx/t/js_fetch.t