Headers middleware configuration for conditional response header injection
22K reputation · 11 Mar 2023, 12:06 UTC
Request-based Header Manipulation
Traefik Proxy utilizes the Headers middleware to inject, modify, or remove HTTP headers at Layer 7. This is commonly used to enforce security policies like HSTS or to pass custom metadata to downstream services via dynamic configuration in YAML or Kubernetes labels.
Conditional Logic Constraints
Current documentation outlines the ability to apply headers globally or per-service. However, there is uncertainty regarding the ability to conditionally inject a response header based on the value of an incoming request header within a single middleware definition, without creating multiple distinct routers for every possible header permutation.
- Requirement: Inject a specific response header only when a corresponding request header is present.
- Constraint: Avoid router proliferation in large-scale deployments.
Does the Headers middleware support conditional logic for response injection based on request attributes? If not, what is the recommended architectural approach to achieve this behavior in Traefik v3.0?