For example, if you specify a set of headers in a route table for service B, a request from service A in your mesh to service B must contain the entire set of headers in order for the request to be routed. For other methods of request matching, see Match incoming requests.

Configuration

In a RouteTable resource, add the following matchers section to your route:

  
...
  http:
  - matchers:
    - headers:
      - name: <header_name>
        value: <header_value>
        regex: <true|false>
        invertMatch: <true|false>
    ...
  
FieldDescription
nameThe name of the header in the request.
valueThe value of the header. If you omit this value, requests that have the header name match regardless of the header’s value.
regexWhether the header value is written as a regular expression. Defaults to false.
invertMatchIf set to true, the result of the match is inverted, or only match if the string is not found. Defaults to false.


For more information, see the Gloo Mesh Enterprise API docs for route tables and for request matching.

Examples

For example, consider the following route table.

  apiVersion: networking.gloo.solo.io/v2
kind: RouteTable
metadata:
  name: headers-match
  namespace: global
spec:
  hosts:
    - 'myapp.global.svc.cluster.local'
  http:
  - matchers:
    - headers:
      - name: <header_name>
        value: <header_value>
        regex: <true|false>
        invertMatch: <true|false>
    forwardTo:
      destinations:
      - ref:
          name: myapp
          namespace: global
          cluster: ${REMOTE_CLUSTER1}
        port:
          number: 8090
        kind: SERVICE
  

To achieve the following example request matches, you might use these combinations of headers settings. Remember that requests must match all specified headers.

Match only header name: Requests to the host that include the header named X-route-to-myapp are routed to the myapp destination.

  
    - headers:
      - name: X-route-to-myapp
  

Match header name and value: Requests to the host that include the header X-route-to-myapp: v1 are routed to the myapp destination.

  
    - headers:
      - name: X-route-to-myapp
        value: "v1"
  

Match header name and regex-defined value: Requests to the host that include headers such as X-route-to-myapp: v1 or X-route-to-myapp: v3 are routed to the myapp destination.

  
    - headers:
      - name: X-route-to-myapp
        value: v.*
        regex: true
  

Match anything except header name and value: Requests to the host that do not include the header X-route-to-myapp: v1 are routed to the myapp destination. Note that requests including headers such as X-route-to-myapp: v2 are matched and forwarded.

  
    - headers:
      - name: X-route-to-myapp
        value: "v1"
        invertMatch: true
  

Next steps

Check out the guides in Forward requests to a destination to further build your route tables based on the destination type, and apply the route tables to your ingress gateway.