Header matching

Specify a set of headers which incoming requests must match in entirety. 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>
    ...
Field Description
name The name of the header in the request.
value The value of the header. If you omit this value, requests that have the header name match regardless of the header’s value.
regex Whether the header value is written as a regular expression. Defaults to false.
invertMatch If 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 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:
    - 'one.solo.io'
  virtualGateways:
    - name: ingress-gateway
      namespace: gloo-mesh
      cluster: ${REMOTE_CLUSTER1}
  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: The ingress gateway forwards all requests to one.solo.io that include the header named X-route-to-myapp to the myapp destination.

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

Match header name and value: The ingress gateway forwards all requests to one.solo.io that include the header X-route-to-myapp: v1 to the myapp destination.

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

Match header name and regex-defined value: The ingress gateway forwards all requests to one.solo.io that include headers such as X-route-to-myapp: v1 or X-route-to-myapp: v3 to the myapp destination.

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

Match anything except header name and value: The ingress gateway forwards all requests to one.solo.io that do not include the header X-route-to-myapp: v1 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.