Skip to content

Update docs for regex matching for HTTPRoutes and GRPCRoutes #182

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 50 additions & 4 deletions content/ngf/how-to/traffic-management/advanced-routing.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ The goal is to create a set of rules that will result in client requests being s

### Deploy the Coffee applications

Begin by deploying the `coffee-v1` and `coffee-v2` applications:
Begin by deploying the `coffee-v1`, `coffee-v2` and `coffee-v3` applications:

```shell
kubectl apply -f https://raw.githubusercontent.com/nginx/nginx-gateway-fabric/v1.6.1/examples/advanced-routing/coffee.yaml
Expand Down Expand Up @@ -108,6 +108,24 @@ spec:
backendRefs:
- name: coffee-v2-svc
port: 80
- matches:
- path:
type: PathPrefix
value: /coffee
headers:
- name: headerRegex
type: RegularExpression
value: "header-[a-z]{1}"
- path:
type: PathPrefix
value: /coffee
queryParams:
- name: queryRegex
type: RegularExpression
value: "query-[a-z]{1}"
backendRefs:
- name: coffee-v3-svc
port: 80
EOF
```

Expand All @@ -116,10 +134,19 @@ This HTTPRoute has a few important properties:
- The `parentRefs` references the gateway resource that we created, and specifically defines the `http` listener to attach to, via the `sectionName` field.
- `cafe.example.com` is the hostname that is matched for all requests to the backends defined in this HTTPRoute.
- The first rule defines that all requests with the path prefix `/coffee` and no other matching conditions are sent to the `coffee-v1` Service.
- The second rule defines two matching conditions. If _either_ of these conditions match, requests are forwarded to the `coffee-v2` Service:
- The second rule defines two matching conditions. If *either* of these conditions match, requests are forwarded to the `coffee-v2` Service:

- Request with the path prefix `/coffee` and header `version=v2`.
- Request with the path prefix `/coffee` and the query parameter `TEST=v2`.

{{< note >}} The match type is `Exact` for both header and query param, by default. {{< /note >}}

- The third rule defines two matching conditions. If *either* of these conditions match, requests are forwarded to the `coffee-v3` Service:

- Request with the path prefix `/coffee` and header `version=v2`
- Request with the path prefix `/coffee` and the query parameter `TEST=v2`
- Request with the path prefix `/coffee` and header `HeaderRegex=Header-[a-z]{1}`.
- Request with the path prefix `/coffee` and the query parameter `QueryRegex=Query-[a-z]{1}`.

{{< note >}} The match type used here is `RegularExpression`. A request will succeed if the header or query parameter value matches the specified regular expression. {{< /note >}}

If you want both conditions to be required, you can define headers and queryParams in the same match object.

Expand Down Expand Up @@ -161,6 +188,25 @@ Server address: 10.244.0.9:8080
Server name: coffee-v2-68bd55f798-s9z5q
```

If we want our request to be routed to `coffee-v3`, then we need to meet the defined conditions. We can include a header matching the regular expression:

```shell
curl --resolve cafe.example.com:$GW_PORT:$GW_IP http://cafe.example.com:$GW_PORT/coffee -H "headerRegex:header-a"
```

or include a query parameter matching the regular expression:

```shell
curl --resolve cafe.example.com:$GW_PORT:$GW_IP http://cafe.example.com:$GW_PORT/coffee?queryRegex=query-a
```

Either request should result in a response from the `coffee-v3` Pod.

```text
Server address: 10.244.0.104:8080
Server name: coffee-v3-66d58645f4-6zsl2
```

---

## Tea applications
Expand Down
6 changes: 3 additions & 3 deletions content/ngf/overview/gateway-api-compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ See the [static-mode]({{< ref "/ngf/reference/cli-help.md#static-mode">}}) comma
- `rules`
- `matches`
- `path`: Partially supported. Only `PathPrefix` and `Exact` types.
- `headers`: Partially supported. Only `Exact` type.
- `queryParams`: Partially supported. Only `Exact` type.
- `headers`: Supported.
- `queryParams`: Supported.
- `method`: Supported.
- `filters`
- `type`: Supported.
Expand Down Expand Up @@ -219,7 +219,7 @@ See the [static-mode]({{< ref "/ngf/reference/cli-help.md#static-mode">}}) comma
- `rules`
- `matches`
- `method`: Partially supported. Only `Exact` type with both `method.service` and `method.method` specified.
- `headers`: Partially supported. Only `Exact` type.
- `headers`: Supported
- `filters`
- `type`: Supported.
- `requestHeaderModifier`: Supported. If multiple filters are configured, NGINX Gateway Fabric will choose the first and ignore the rest.
Expand Down
Loading