Skip to content

modify response headers values based on response body contents #62

Open

Description

@webngt

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.

Activity

  1. aysee commented on Apr 1, 2021

    @aysee

    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?

  2. PiotrSikora commented on Apr 2, 2021

    @PiotrSikora
    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.

  3. aysee commented on Apr 3, 2021

    @aysee

    @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

  4. PiotrSikora commented on Apr 3, 2021

    @PiotrSikora
    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.

  5. PiotrSikora commented on Apr 16, 2021

    @PiotrSikora
    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.

  6. aysee commented on Apr 19, 2021

    @aysee

    @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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions