Besides redirecting traffic, blocking hosts and decrypting SSL, ProxyMapService can edit HTTP headers on the fly. Two kinds of rules are available: RequestHeaders — add or replace headers sent to the upstream server (for example, to inject an Authorization header for upstream authentication that the client software does not support), and ResponseHeaders — edit headers sent back to the client (for example, to strip Server or X-Powered-By).
The rules work for plain HTTP and, when SSL decryption is enabled, for HTTPS too — including HTTP/2 traffic on both sides. The client and the server keep speaking their own protocols; the proxy quietly adjusts the headers in between.
What you can do with it
A few real-world use cases:
- Upstream authentication — inject
"Authorization": "Bearer ${API_TOKEN}"for a specific host whose API requires a token the client does not send. The token lives in an environment variable, not in the config file. - Traffic tagging — add an
X-Gateway: ProxyMapServiceheader to every request so the upstream can tell proxy traffic apart. - Cleanup — remove
Server,X-Powered-By, trackingCookies or any other headers from responses before they reach the client. - Proxy authentication — add or strip
Proxy-Authorizationfor the next hop.
Configuration: three levels, merged
A rule has two properties: Set (a name → value map: replace every existing header with the same name and append the new value) and Remove (a list of header names to delete). Names are compared case-insensitively in both.
The rules are configured at three levels, and the levels are merged:
- global — the
HTTPsection (HTTP:RequestHeaders/HTTP:ResponseHeaders); Listen— inside aProxyMappingsentry, applies to all traffic of that listening port range;HostRule— inside theHostRulessection, applies only to the matching host (applied when the rule matches and its action is notDeny).
Precedence: global → Listen → HostRule. When merging, Set is merged by key — a higher level replaces the values of the same keys and adds new ones — and the Remove lists are combined. This makes it convenient to define a broad “baseline” globally and add host-specific rules on top.
Example — global rules plus a per-host Authorization injection:
"ProxyMappings": [
{
"Listen": {
"Port": 5001,
"DecryptSSL": true
}
}
],
"HTTP": {
"RequestHeaders": {
"Set": {
"X-Gateway": "ProxyMapService"
},
"Remove": [
"Proxy-Authorization"
]
},
"ResponseHeaders": {
"Remove": [
"Server",
"X-Powered-By"
]
}
},
"HostRules": {
"Items": [
{
"HostName": "api.example.com",
"RequestHeaders": {
"Set": {
"Authorization": "Bearer ${API_TOKEN}"
},
"Remove": [
"Cookie"
]
}
}
]
}
With this configuration every request gets X-Gateway and loses Proxy-Authorization; every response loses Server and X-Powered-By; and requests to api.example.com additionally get an Authorization: Bearer ... header and lose their Cookie headers.
${VARIABLE} placeholders
Set values support ${VARIABLE} placeholders substituted with environment variables:
"Authorization": "Bearer ${API_TOKEN}"
The details that matter:
- a missing variable is substituted with an empty string, and the whole resolved value is trimmed — so
"Bearer ${UNSET}"becomesBearer, notBearerwith a trailing space; - several placeholders can be used in one value:
"${USER}-${REGION}"; - CR/LF characters are stripped from the resolved value. This is a deliberate protection against header injection: even if an environment variable somehow contains a newline, it cannot smuggle an extra header into the request.
Keeping secrets in environment variables instead of the JSON config also means the same appsettings.Production.json can be committed or shared, while the actual tokens stay in the environment of the service.
What is never touched
Two kinds of headers are off-limits on purpose:
- HTTP/2 pseudo-headers (
:method,:path,:authority,:status, …). Even if a rule names one inSetorRemove, it is ignored — these headers define the request line and the target host, and rewriting them is the job of the dedicated Host override mechanism, not of header rules. - Transport framing headers (
Content-Length,Transfer-Encoding) must not be modified: the proxy tracks the body length through these headers, and breaking them would corrupt the body tracking.
Where it works
| Scenario | Request headers | Response headers |
|---|---|---|
| HTTP/1.1 client → HTTP/1.1 server | ✅ | ✅ |
| HTTP/1.1 client → HTTP/2 server (translation) | ✅ | ✅ |
| HTTP/2 client → HTTP/2 server | ✅ | not yet (forwarded as is) |
| Responses served from the cache | — | ✅ |
| TLS passthrough (no decryption) | — | — |
Notes:
- For HTTPS, SSL decryption must be enabled — otherwise the proxy sees only encrypted bytes and there is nothing to edit. The rules ride on the same
DecryptSSL: trueswitch as the rest of the traffic inspection. - In transparent h2 → h2 sessions response header rules are not applied yet. If response editing is required for such a host, use the h1 → h2 translation (an HTTP/1.1 upstream) — request rules work everywhere.
- The same rules also apply to responses served by the proxy itself from the cache.
Under the hood: HTTP/2 header rewriting
Editing HTTP/2 headers is a different beast from HTTP/1.1, where a header block is just a list of lines. In HTTP/2 the headers are an HPACK-encoded block that can be split across HEADERS and CONTINUATION frames, and both sides keep a dynamic table of previously seen headers — a later frame may reference a header by index instead of sending it again.
The proxy handles this with a streaming rewriter that sits in the h2 → h2 path:
- continuation blocks are reassembled — a header block split across HEADERS + CONTINUATION frames is decoded as one block and, if it does not fit into one frame (the payload limit is 16 384 bytes), split back into HEADERS + CONTINUATION on the way out;
- the client’s dynamic table state is kept — frames that reference previously seen headers by index decode correctly, even though the proxy never forwards those index references;
- re-encoded blocks contain only non-indexing literals — the proxy never emits indexed representations or dynamic table size updates towards the server, so its own encoding can never desynchronize the server’s table.
If something goes wrong at this level, the h2 connection is torn down rather than silently forwarding a corrupted stream.
Summary
RequestHeaders / ResponseHeaders is a small but complete mini-DSL inside the proxy configuration: two operations (Set, Remove), three configuration levels with predictable merging, environment-variable placeholders with injection protection, and consistent behavior across HTTP/1.1 and HTTP/2. Combined with HostRules it covers the typical “the client won’t send the header / the server shouldn’t see the header” scenarios without touching the client or the server.