Prompt
How do I do header rewrites at the network edge?
Latest observation
Oct 26, 2026
OpenAI APIWeb search: off
To do header rewrites at the network edge, you typically use one of these components:
- API gateway (Kong, Apigee, Ambassador, NGINX, Traefik)
- Reverse proxy / edge proxy (NGINX, Envoy, HAProxy, Caddy)
- CDN / edge platform (Cloudflare Workers, Fastly Compute, Akamai EdgeWorkers)
- Load balancer with L7 rules (AWS ALB, Azure Application Gateway, GCP HTTPS LB with proxy rules)
What “header rewrite” usually means
You can:
- Add a header
- Remove a header
- Rename a header
- Overwrite a header value
- Conditionally rewrite based on path, host, method, IP, etc.
Examples:
X-Forwarded-ForhandlingAuthorizationtransformationHostheader normalization- Security headers like
Strict-Transport-Security,Content-Security-Policy
Common ways to implement it
1) NGINX
Example: add, remove, and overwrite headers.
location /api/ {
proxy_pass http://backend;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Request-Id $request_id;
proxy_set_header Authorization "";
add_header X-Edge-Region "us-east-1" always;
}
Notes:
proxy_set_headerchanges headers sent to the upstreamadd_headerchanges headers sent to the client- Setting a header to
""effectively removes it from upstream requests
2) Envoy
Use route/header manipulation or Lua/WASM/ext_proc.
Example route config conceptually:
- add/remove request headers
- add/remove response headers
- match on route and rewrite conditionally
Envoy is a strong choice if you need:
- complex routing
- high performance
- service mesh integration
- policy-driven rewrites
3) Cloudflare Workers
Great for edge rewrites in code.
export default {
async fetch(request) {
const headers = new Headers(request.headers);
headers.set("X-Edge-Tag", "cloudflare");
headers.delete("Authorization");
const newRequest = new Request(request, { headers });
return fetch(newRequest);
}
};
Use this when you need:
- logic-based header decisions
- geo/device-based behavior
- custom auth/header normalization
4) Fastly VCL / Compute
Fastly can rewrite request/response headers at the edge.
Conceptually:
- modify
req.http.*for requests - modify
resp.http.*for responses
5) AWS / Cloud / LB rules
Some platforms support limited header transforms:
- add/overwrite response headers
- redirect/rewrite based on path/host
- more advanced logic usually needs a proxy or edge function
Recommended pattern
If you want a practical architecture:
- Put an edge proxy/gateway in front of your services
- Normalize incoming headers there
- Strip unsafe client-supplied headers
- Add trusted internal headers
- Forward only what your upstream needs
Security best practices
- Do not trust client-supplied
X-Forwarded-*unless your edge overwrites them - Remove spoofable headers like:
X-Forwarded-ForX-Real-IPX-Forwarded-HostX-Forwarded-Proto
- Add internal-only headers only at the edge
- Be careful not to rewrite
Authorizationunless you know exactly what the backend expects - Log rewrite decisions for debugging and auditing
If you want the simplest answer
Use:
- NGINX for basic header rewrites
- Envoy for advanced routing/policy
- Cloudflare Workers/Fastly Compute for programmable edge logic
If you tell me what edge platform you’re using (NGINX, Cloudflare, AWS, Envoy, etc.) and whether you’re rewriting request headers, response headers, or both, I can give you an exact config/example.