Content-Length getting updated to 0 in multipart HTTP requests

My issue:
nginx is setting content-length to 0 multipart http requests at nginx before forwarding request to node.js application. form-boundary value is also getting update to that of the previous request. However, all the other headers remain intact.

How I encountered the problem:
A node.js application that is behind the nginx proxy is unable to read multipart http requests and returns a stream ended unexpectedly error. Upon observing the headers we notice that the Content-Length is set to 0, even though this is not the case in the request submitted from the browser.

Note that we do not encounter this error when the request is submitted directly to the node.js application, bypassing nginx.

Solutions I’ve tried:
Updating and testing following configurations on nginx

  1. gzip off and proxy_buffering off
  2. gzip off
  3. proxy_buffering off and proxy_request_buffering off;
  4. more_clear_headers Content-Length
  5. Removing proxy_max_temp_file_size 0
  6. proxy_set_header Connection “”
  7. client_max_body_size 200m

Version of NGINX or NGINX adjacent software (e.g. NGINX Gateway Fabric):
nginx 1.28.0

What could be the most likely cause for this issue where the Content-Length header is getting modified?

Hi @nalakag-mvsi!

I have never encountered this issue myself, but this thread has a few suggestions that you might find useful https://serverfault.com/q/482875. In short, this might be due to a mixture of using:
a) A multipart/chunked request, in which case you can’t really use Content-Length
or
b) Not changing the default proxy_http_version, in which case the upstream connection is being made using HTTP/1

You also seem to be able to use the more_clear_headers module, which indicates you aren’t using our NGINX build. It’s not likely, but this might lead to some potential diferences/issues in so far as NGINX behaviour goes.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.