Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
orangetangerine opened this issue Jul 1, 2021 · 2 comments

Comments

@orangetangerine
Copy link

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
Copy link
Contributor

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
Copy link
Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants