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

modify response headers values based on response body contents #62

Open
webngt opened this issue Oct 21, 2020 · 6 comments
Open

modify response headers values based on response body contents #62

webngt opened this issue Oct 21, 2020 · 6 comments

Comments

@webngt
Copy link

webngt commented Oct 21, 2020

Is it possible to modify response header values based on response body contents? For example, if I match a certain pattern in onResponseBody I want to replace :status header value from 200 to 401 or 403 value.

According to documentation, Header API is only effective from onRequestHeader/onResponseHeader. So my task seems to be impossible to implement. Or maybe you can point to some kind of workaround?

Cheers,
Alexander.

@aysee
Copy link

aysee commented Apr 1, 2021

I have a similar use case. We need to update crc-32 header after we modify response body. However, according to the docs, header modification is not allowed when we process body.
Is there a workaround available?

@PiotrSikora
Copy link
Member

@webngt buffering complete responses is not supported, sorry (see: proxy-wasm/proxy-wasm-cpp-host#143 (comment)).

@aysee if the consumer supports it, then you should be sending updated CRC-32 value in HTTP trailers instead of headers.

@aysee
Copy link

aysee commented Apr 3, 2021

@PiotrSikora thank you for your suggestion of using HTTP trailers! I tried to use them in my sandbox project, but onResponseTrailers and onRequestTrailers are not being called. Do you have any example of how to use them?
Here is what I have in my Context:

  FilterTrailersStatus onRequestTrailers(uint32_t) override;
  FilterTrailersStatus onResponseTrailers(uint32_t) override;

Here is the implementation itself (just logs for debug purposes):

FilterTrailersStatus ExampleContext::onRequestTrailers(uint32_t) {
    LOG_INFO(std::string("onRequestTrailers ") + std::to_string(id()));
    return FilterTrailersStatus::Continue;
}

FilterTrailersStatus ExampleContext::onResponseTrailers(uint32_t) {
    LOG_INFO(std::string("onResponseTrailers ") + std::to_string(id()));
    return FilterTrailersStatus::Continue;
}

on*Body methods also return FilterDataStatus::Continue

@PiotrSikora
Copy link
Member

@PiotrSikora thank you for your suggestion of using HTTP trailers! I tried to use them in my sandbox project, but onResponseTrailers and onRequestTrailers are not being called. Do you have any example of how to use them?

Those callbacks are called only if trailers already exist (i.e. if they were received from upstream)... and I've now realized that we don't support setting trailers if they don't already exist in Envoy, see: envoyproxy/envoy#15831.

@PiotrSikora
Copy link
Member

@aysee that PR was merged and it's included in the Envoy v1.18.0 release. There are examples for how to use it in that PR.

@aysee
Copy link

aysee commented Apr 19, 2021

@PiotrSikora thank you so much for such a quick implementation! I appreciate it!

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

3 participants