Skip to content

Strange error 400 from ngx.fetch with body #930

@pyhedgehog

Description

@pyhedgehog

Describe the bug

If I want to use ngx.fetch to forward request to some other server (aka proxy_pass) I'm copying r.headersIn and passing r.requestText as body. But this method fails.

I've found that I can fix bug by adding headers.delete('content-length');. This makes me think that in such config ngx.fetch passes two content-length headers to server and it fails to parse it.
https://github.com/nginx/njs/blob/master/nginx/ngx_js_fetch.c#L691

To reproduce

I've created gist with complete nginx.conf and js module:
https://gist.github.com/pyhedgehog/8f3bf0e8373aeb3f75c7b23347a1e578#file-showbug-md

Expected behavior

Possible solutions:

  1. Skip content-length from input headers.
  2. Skip generating content-length if it already in headers (like with has_host).
  3. Document this behavior.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions