Header-based Routing
Ambassador Edge Stack can route to target services based on HTTP headers with the headers
and regex_headers
specifications. Multiple mappings with different annotations can be applied to construct more complex routing rules.
The headers
Annotation
The headers
attribute is a dictionary of header
: value
pairs. Ambassador Edge Stack will only allow requests that match the specified header
: value
pairs to reach the target service.
You can also set the value
of a header to true
to test for the existence of a header.
A Basic Example
---apiVersion: getambassador.io/v2kind: Mappingmetadata:name: quote-backendspec:prefix: /backend/service: quoteheaders:x-quote-mode: backendx-random-header: datawire
will allow requests to /backend/ to succeed only if the x-quote-mode header has the value backend and the x-random-header has the value datawire
.
A Conditional Example
---apiVersion: getambassador.io/v2kind: Mappingmetadata:name: quote-modespec:prefix: /backend/service: quote-modeheaders:x-quote-mode: true---apiVersion: getambassador.io/v2kind: Mappingmetadata:name: quote-regularspec:prefix: /backend/service: quote-regular
will send requests that contain the x-quote-mode header to the quote-mode target, while routing all other requests to the quote-regular target.
regex_headers
The following mapping will route mobile requests from Android and iPhones to a mobile service:
---apiVersion: getambassador.io/v2kind: Mappingmetadata:name: quote-backendspec:regex_headers:user-agent: "^(?=.*\\bAndroid\\b)(?=.*\\b(m|M)obile\\b).*|(?=.*\\biPhone\\b)(?=.*\\b(m|M)obile\\b).*$"prefix: /backend/service: quote
Questions?
We’re here to help. If you have questions, join our Slack or contact us.