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 modify HTTP header "Content-Length" in onRequestBody/onResponseBody #146

Open
coolg92003 opened this issue Nov 30, 2022 · 2 comments

Comments

@coolg92003
Copy link

Current, I use WASM to modify request/response body: a

  1. Assume the orignal message body:
    {"name":"cliff"}
    'content-length', '16'
  2. in onRequestBody()
    After modify, then the body size will be below 3 conditions:
  3. the new body size == the original body size, Perfect
    in server side, got {"name":"world"}
  4. the new body size > the original body size, this is also Ok, my solution is to remove "Content-Length" unconditionally when calling onRequestHeader()
    in server side, got {"name":"hello world"}
  5. the new body size > the original body size
    I Can't handle this case.
    in server side, got {"name":"leo"}f"}, the additional ff is there
    the ugly way is to set requestbody from<f"}>, then server side get <{"name":"leo"} >
    then server side got extra 3 spaces.
    Therefore, would you help provide one way to modify the "Content-Length" in onRequestBody/onResponseBody after modify the message body.

Below is code:
//std::string l_new_data("{"new_data":"new_data_value_add_by_cliff"}");
std::string l_new_data("{"new":"new"}");
size_t l_new_size = l_new_data.size();
WasmResult l_set_result = setBuffer(WasmBufferType::HttpRequestBody, 0, l_new_size, l_new_data, &l_new_size);
LOG_TRACE(std::string(HSSC) + std::string("set status=") + (l_set_result == WasmResult::Ok ? std::string("Ok"):std::string("Not_ok")));
LOG_TRACE(std::string(HSSC) + std::string("After setBuffer(") + l_new_data + std::string("), pReqBodyBuffSize=")
+ std::to_string(pReqBodyBuffSize) + std::string(" and newbuff size=") + std::to_string(l_new_size));

Notes: no matter which way below, it doesn't work
//addRequestHeader("Content-Length", std::to_string(l_new_size));
//removeRequestHeader("Content-Length");

thanks
Cliff

@coolg92003
Copy link
Author

coolg92003 commented Nov 30, 2022

This is good link(#127), but it doesn't meet the need

@coolg92003
Copy link
Author

After reading #124,
think it is reasonable to remove "Content-Length" because after modifying Request Body in onRequestBody(), there is no chance to modify "Content-Length" since it has been sent out

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

1 participant