envoy: Cannot modify body in `ext_proc` filter due to clearance of `content-length` header

Title: Cannot modify body in ext_proc filter due to clearance of content-length header

Description: Currently in the ext_proc filter I cannot modify the body of the request, (and potentially the response but I haven’t tested), because a modify_body request will always result in the clearance of the content-length header. The filter should either allow the user to set it themselves, or set the header based on the final modified value.

The offending code is here: https://github.com/envoyproxy/envoy/blob/0a672f829fcc02681de38656b964ebae00c58608/source/extensions/filters/http/ext_proc/processor_state.cc#L231-L233

Because the header clear happens after the header mutations, there’s no opportunity to set the content-length header properly.

Repro steps: To reproduce this bug I have a repo based off of @gbrail’s rust stubs. https://github.com/EItanya/envoy-ext-proc-stubs-rust First, run cargo build to build the rust server. Then download envoy v1.26.3. Finally run all of the necessary pieces.

  1. python3 server.py
  2. ./target/debug/server
  3. <envoy> -c envoy.yaml --component-log-level ext_proc:trac
  4. `curl -X POST -d ‘{“Hello”: “server”}’ http://localhost:8000/service/2

The curl request will fail because server.py does not receive the content-length header because it is cleared.

I am happy to create a PR to remove the offending header clears, but I want to better understand why they are there, and what the intentional behavior is. Also, there is an integ test that is supposed to test this behavior, but in the test logs I see that the content-length header is not set, so I think it’s passing when it should not be.

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 42 (39 by maintainers)

Most upvoted comments

I think it is a fair point. In http 1.1, we can make chunked encoding optional in ext_proc buffer mode where content length could be set correctly. In other words, it is up to user to decide whether they want to use content_length or chunked encoding in this case.

/assign @tyxia