Skip to content

Commit 145c74f

Browse files
authored
Update docs for regex matching for HTTPRoutes and GRPCRoutes (#182)
Add documentation for regex matching
1 parent f24cd66 commit 145c74f

File tree

2 files changed

+53
-7
lines changed

2 files changed

+53
-7
lines changed

content/ngf/how-to/traffic-management/advanced-routing.md

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ The goal is to create a set of rules that will result in client requests being s
4141

4242
### Deploy the Coffee applications
4343

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

4646
```shell
4747
kubectl apply -f https://raw.githubusercontent.com/nginx/nginx-gateway-fabric/v1.6.1/examples/advanced-routing/coffee.yaml
@@ -108,6 +108,24 @@ spec:
108108
backendRefs:
109109
- name: coffee-v2-svc
110110
port: 80
111+
- matches:
112+
- path:
113+
type: PathPrefix
114+
value: /coffee
115+
headers:
116+
- name: headerRegex
117+
type: RegularExpression
118+
value: "header-[a-z]{1}"
119+
- path:
120+
type: PathPrefix
121+
value: /coffee
122+
queryParams:
123+
- name: queryRegex
124+
type: RegularExpression
125+
value: "query-[a-z]{1}"
126+
backendRefs:
127+
- name: coffee-v3-svc
128+
port: 80
111129
EOF
112130
```
113131

@@ -116,10 +134,19 @@ This HTTPRoute has a few important properties:
116134
- The `parentRefs` references the gateway resource that we created, and specifically defines the `http` listener to attach to, via the `sectionName` field.
117135
- `cafe.example.com` is the hostname that is matched for all requests to the backends defined in this HTTPRoute.
118136
- The first rule defines that all requests with the path prefix `/coffee` and no other matching conditions are sent to the `coffee-v1` Service.
119-
- The second rule defines two matching conditions. If _either_ of these conditions match, requests are forwarded to the `coffee-v2` Service:
137+
- The second rule defines two matching conditions. If *either* of these conditions match, requests are forwarded to the `coffee-v2` Service:
138+
139+
- Request with the path prefix `/coffee` and header `version=v2`.
140+
- Request with the path prefix `/coffee` and the query parameter `TEST=v2`.
141+
142+
{{< note >}} The match type is `Exact` for both header and query param, by default. {{< /note >}}
143+
144+
- The third rule defines two matching conditions. If *either* of these conditions match, requests are forwarded to the `coffee-v3` Service:
120145

121-
- Request with the path prefix `/coffee` and header `version=v2`
122-
- Request with the path prefix `/coffee` and the query parameter `TEST=v2`
146+
- Request with the path prefix `/coffee` and header `HeaderRegex=Header-[a-z]{1}`.
147+
- Request with the path prefix `/coffee` and the query parameter `QueryRegex=Query-[a-z]{1}`.
148+
149+
{{< 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 >}}
123150

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

@@ -161,6 +188,25 @@ Server address: 10.244.0.9:8080
161188
Server name: coffee-v2-68bd55f798-s9z5q
162189
```
163190

191+
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:
192+
193+
```shell
194+
curl --resolve cafe.example.com:$GW_PORT:$GW_IP http://cafe.example.com:$GW_PORT/coffee -H "headerRegex:header-a"
195+
```
196+
197+
or include a query parameter matching the regular expression:
198+
199+
```shell
200+
curl --resolve cafe.example.com:$GW_PORT:$GW_IP http://cafe.example.com:$GW_PORT/coffee?queryRegex=query-a
201+
```
202+
203+
Either request should result in a response from the `coffee-v3` Pod.
204+
205+
```text
206+
Server address: 10.244.0.104:8080
207+
Server name: coffee-v3-66d58645f4-6zsl2
208+
```
209+
164210
---
165211

166212
## Tea applications

content/ngf/overview/gateway-api-compatibility.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,8 @@ See the [static-mode]({{< ref "/ngf/reference/cli-help.md#static-mode">}}) comma
167167
- `rules`
168168
- `matches`
169169
- `path`: Partially supported. Only `PathPrefix` and `Exact` types.
170-
- `headers`: Partially supported. Only `Exact` type.
171-
- `queryParams`: Partially supported. Only `Exact` type.
170+
- `headers`: Supported.
171+
- `queryParams`: Supported.
172172
- `method`: Supported.
173173
- `filters`
174174
- `type`: Supported.
@@ -219,7 +219,7 @@ See the [static-mode]({{< ref "/ngf/reference/cli-help.md#static-mode">}}) comma
219219
- `rules`
220220
- `matches`
221221
- `method`: Partially supported. Only `Exact` type with both `method.service` and `method.method` specified.
222-
- `headers`: Partially supported. Only `Exact` type.
222+
- `headers`: Supported
223223
- `filters`
224224
- `type`: Supported.
225225
- `requestHeaderModifier`: Supported. If multiple filters are configured, NGINX Gateway Fabric will choose the first and ignore the rest.

0 commit comments

Comments
 (0)