envoyproxy/envoy

Ability to rename request headers

Open

#8947 aperta il 8 nov 2019

Vedi su GitHub
 (2 commenti) (1 reazione) (0 assegnatari)C++ (5373 fork)batch import
api/v3design proposalhelp wanted

Metriche repository

Star
 (27.997 star)
Metriche merge PR
 (Merge medio 8g) (378 PR mergiate in 30 g)

Descrizione

Now that we can use request headers in the request_headers_to_add option, one might want to rename a header:

    request_headers_to_remove:
    - x-header
    request_headers_to_add:
    - header:
        key: x-new-name
        value: "%REQ(x-header)%"

However this will not work, because HeaderParser::evaluateHeaders removes headers first.

void HeaderParser::evaluateHeaders(Http::HeaderMap& headers,
                                   const StreamInfo::StreamInfo& stream_info) const {
  // Removing headers in the headers_to_remove_ list first makes
  // remove-before-add the default behavior as expected by users.

This was introduced in #5052 : "reverses the order of header evaluation as a solution to deduplicating request/response headers".

There are multiple ways to approach this header-renaming issue.

One is to add request_headers_to_post_remove which will be used after request_headers_to_add.

Another would be request_headers_to_pre_add but "post-remove" is better because headers-to-remove is just a list of names, when headers-to-add is much bulkier.

The most trivial option is to introduce a map<string, string> rename_headers.

There is also an option to add a preserve_request_headers list, to store original request headers somewhere in StreamInfo, and add a new formatter, e.g. %PREQ(header-name)% to access them. It might be useful because such headers won't be removed or modified by filters. However for now I just want to rename a couple of headers and this would be an overkill.

So, how about a new post-remove header list?

Guida contributor