Skip to content

feat: add negate_match feature for propagate regular expressions #87

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
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
10 changes: 8 additions & 2 deletions docs/router/proxy-capabilities/request-headers-operations.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ headers:
- op: "propagate"
matching: (?i)^X-Custom-.*

- op: "propagate"
matching: ^(Header-1|Key)$
negate_match: true # Ensure that all headers except the Header-1 and Key are propagated

# Sets the value when the header was not set
- op: "propagate"
named: "X-User-Id"
Expand Down Expand Up @@ -61,11 +65,13 @@ The `subgraphs` section allows to propagate headers for specific subgraphs. The

Currently, we support the following header rules:

* **propagate **- Forwards all matching client request headers to the subgraphs. You can choose between one of the following matchers:
* **propagate** - Forwards all matching client request headers to the subgraphs. You can choose between one of the following matchers:

* `named` - It exactly matches on the header name.

* `matching`** - **Regex matches on the header name. You can use [regex101.com](https://regex101.com/) to test your regexes. Go to the website and select `Golang` on the left panel. **Note:** The Router *never* propagates [hop-by-hop headers](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers#hop-by-hop_headers) (such as `Connection`) when propagating by regex.
* `matching` - Regex matches on the header name. You can use [regex101.com](https://regex101.com/) to test your regexes. Go to the website and select `Golang` on the left panel. **Note:** The Router *never* propagates [hop-by-hop headers](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers#hop-by-hop_headers) (such as `Connection`) when propagating by regex.

* `negate_match` - If set to true, the result of the `matching` regex will be inverted. This is useful for simulating negative lookahead behavior, which is not natively supported.

* `rename`: Replaces the identified header based on its name or matching criteria and transfers the value to the newly specified header.

Expand Down
21 changes: 14 additions & 7 deletions docs/router/proxy-capabilities/response-header-operations.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ By default, no response headers are forwarded for security reasons. To enable re
# for the full list of configuration options.

headers:
all: # Header rules for all subgraph requests.
all: # Header rules for all subgraph responses.
response:
- op: "propagate" # Forward a client header
named: X-Test-Header # Exact match (Use the canonicalized version)
Expand All @@ -43,6 +43,11 @@ headers:
matching: (?i)^X-Custom-.* # Regex match (Case insensitive)
algorithm: "last_write"

- op: "propagate"
matching: ^(Header-1|Key)$
negate_match: true # Ensure that all headers except the Header-1 and Key are propagated
algorithm: "last_write"

- op: "propagate"
named: "X-User-Id"
default: "123" # Set the value when the header was not set
Expand Down Expand Up @@ -71,17 +76,19 @@ The `subgraphs` section allows to propagate headers for specific subgraphs. The

Currently, we support the following header rules:

* **propagate **- Forwards all matching response headers from the subgraphs. You can choose between the following options:
* **propagate** - Forwards all matching response headers from the subgraphs. You can choose between the following options:

* `algorithm` - This defines the algorithm, selecting between `first_write`, `last_write`, and `append`

* **algorithm - **This defines the algorithm, selecting between `first_write`, `last_write`, and `append`
* `named` - It exactly matches on the header name.

* **named** - It exactly matches on the header name.
* `matching` - Regex matches on the header name. You can use[regex101.com](https://regex101.com/) to test your regexes. Go to the website and select `Golang` on the left panel. **Note:** The Router *never* propagates [hop-by-hop headers](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers#hop-by-hop_headers) (such as `Connection`) when propagating by regex.

* **matching - **Regex matches on the header name. You can use[regex101.com](https://regex101.com/) to test your regexes. Go to the website and select `Golang` on the left panel. **Note:** The Router *never* propagates [hop-by-hop headers](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers#hop-by-hop_headers) (such as `Connection`) when propagating by regex.
* `negate_match` - If set to true, the result of the `matching` regex will be inverted. This is useful for simulating negative lookahead behavior, which is not natively supported.

* **rename**: Replaces the identified header based on its name or matching criteria and transfers the value to the newly specified header.
* `rename` - Replaces the identified header based on its name or matching criteria and transfers the value to the newly specified header.

* **default**: Fallback to this value when the `named`, `matching` or `rename` header could not be found.
* `default` - Fallback to this value when the `named`, `matching` or `rename` header could not be found.

* `set` - Sets a header on the request forward to the subgraph. You must set the following values:

Expand Down