envoyproxy / envoyproxy/envoy

Ability to rename request headers

Open
#8,947 2 comments 1 reaction 0 assignees View on GitHub
api/v3 design proposal help wanted
Dominant language
C++
Stars
28.9k
Forks
5.6k
Avg merge
1d 22h
Merged PRs (30d)
430

Description

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 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?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.