proxy-wasm / proxy-wasm-cpp-sdk

WebAssembly for Proxies (C++ SDK)
Apache License 2.0
140 stars 68 forks source link

How to update content-length header after modifying response body via setBuffer(WasmBufferType::HttpResponseBody) ? #124

Closed orangetangerine closed 3 years ago

orangetangerine commented 3 years ago

Hi, I have a json response like {"foo": "bar"}. It's content-length is 14 I added a wasm to wrap the json response to sth like {"code": 0, "err": "", data: {"foo": "bar"}}. It's content-length is 44. I tried calling addResponseHeader("content-length", "44") and replaceResponseHeader("content-length", "44") in onResponseBody. Neither worked. And curl complains:curl: (18) transfer closed with 30 bytes remaining to read`.

How can I update content-length after response body is modified? Thanks.

PiotrSikora commented 3 years ago

No, you cannot update headers after modifying resposne body, since headers are already sent to the client.

However, you don't really need the Content-Length header, and you can safely remove it before modifying the body.

orangetangerine commented 3 years ago

Thanks!