# HeaderMatch

Used to generate header matching methods.

Obtainable from: HeaderMatch.valueDoesNotEndWith, HeaderMatch.valueDoesNotMatchRegex, HeaderMatch.valueDoesNotStartWith, HeaderMatch.valueEndsWith, HeaderMatch.valueIs, HeaderMatch.valueIsNot, HeaderMatch.valueMatchesRegex, HeaderMatch.valueStartsWith, HeaderMatch.valuesIsInRange, HeaderMatch.valuesIsNotInRange

- Source: [`aws-appmesh/lib/header-match.ts`](https://github.com/aws/aws-cdk/blob/v2.278.0/packages/aws-cdk-lib/aws-appmesh/lib/header-match.ts#L17)

## Example

TypeScript:

```ts
declare const router: appmesh.VirtualRouter;
declare const node: appmesh.VirtualNode;

router.addRoute('route-http2', {
  routeSpec: appmesh.RouteSpec.http2({
    weightedTargets: [
      {
        virtualNode: node,
      },
    ],
    match: {
      path: appmesh.HttpRoutePathMatch.exactly('/exact'),
      method: appmesh.HttpRouteMethod.POST,
      protocol: appmesh.HttpRouteProtocol.HTTPS,
      headers: [
        // All specified headers must match for the route to match.
        appmesh.HeaderMatch.valueIs('Content-Type', 'application/json'),
        appmesh.HeaderMatch.valueIsNot('Content-Type', 'application/json'),
      ],
      queryParameters: [
        // All specified query parameters must match for the route to match.
        appmesh.QueryParameterMatch.valueIs('query-field', 'value')
      ],
    },
  }),
});
```

Python:

```python
# router: appmesh.VirtualRouter
# node: appmesh.VirtualNode

router.add_route("route-http2",
    route_spec=appmesh.RouteSpec.http2(
        weighted_targets=[appmesh.WeightedTarget(
            virtual_node=node
        )
        ],
        match=appmesh.HttpRouteMatch(
            path=appmesh.HttpRoutePathMatch.exactly("/exact"),
            method=appmesh.HttpRouteMethod.POST,
            protocol=appmesh.HttpRouteProtocol.HTTPS,
            headers=[
                # All specified headers must match for the route to match.
                appmesh.HeaderMatch.value_is("Content-Type", "application/json"),
                appmesh.HeaderMatch.value_is_not("Content-Type", "application/json")
            ],
            query_parameters=[
                # All specified query parameters must match for the route to match.
                appmesh.QueryParameterMatch.value_is("query-field", "value")
            ]
        )
    )
)
```

Java:

```java
VirtualRouter router;
VirtualNode node;

router.addRoute("route-http2", RouteBaseProps.builder()
        .routeSpec(RouteSpec.http2(HttpRouteSpecOptions.builder()
                .weightedTargets(List.of(WeightedTarget.builder()
                        .virtualNode(node)
                        .build()))
                .match(HttpRouteMatch.builder()
                        .path(HttpRoutePathMatch.exactly("/exact"))
                        .method(HttpRouteMethod.POST)
                        .protocol(HttpRouteProtocol.HTTPS)
                        .headers(List.of(HeaderMatch.valueIs("Content-Type", "application/json"), HeaderMatch.valueIsNot("Content-Type", "application/json")))
                        .queryParameters(List.of(QueryParameterMatch.valueIs("query-field", "value")))
                        .build())
                .build()))
        .build());
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
VirtualRouter router;
VirtualNode node;

router.AddRoute("route-http2", new RouteBaseProps {
    RouteSpec = RouteSpec.Http2(new HttpRouteSpecOptions {
        WeightedTargets = new [] { new WeightedTarget {
            VirtualNode = node
        } },
        Match = new HttpRouteMatch {
            Path = HttpRoutePathMatch.Exactly("/exact"),
            Method = HttpRouteMethod.POST,
            Protocol = HttpRouteProtocol.HTTPS,
            Headers = new [] { HeaderMatch.ValueIs("Content-Type", "application/json"), HeaderMatch.ValueIsNot("Content-Type", "application/json") },
            QueryParameters = new [] { QueryParameterMatch.ValueIs("query-field", "value") }
        }
    })
});
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
var router VirtualRouter
var node VirtualNode

router.addRoute(jsii.String("route-http2"), &RouteBaseProps{
	RouteSpec: appmesh.RouteSpec_Http2(&HttpRouteSpecOptions{
		WeightedTargets: []WeightedTarget{
			&WeightedTarget{
				VirtualNode: node,
			},
		},
		Match: &HttpRouteMatch{
			Path: appmesh.HttpRoutePathMatch_Exactly(jsii.String("/exact")),
			Method: appmesh.HttpRouteMethod_POST,
			Protocol: appmesh.HttpRouteProtocol_HTTPS,
			Headers: []HeaderMatch{
				appmesh.HeaderMatch_ValueIs(jsii.String("Content-Type"), jsii.String("application/json")),
				appmesh.HeaderMatch_ValueIsNot(jsii.String("Content-Type"), jsii.String("application/json")),
			},
			QueryParameters: []QueryParameterMatch{
				appmesh.QueryParameterMatch_ValueIs(jsii.String("query-field"), jsii.String("value")),
			},
		},
	}),
})
```

## Initializer

TypeScript:

```ts
new HeaderMatch()
```

Python:

```python
HeaderMatch()
```

Java:

```java
new HeaderMatch()
```

C# / .NET:

```csharp
new HeaderMatch()
```

Golang:

```go
NewHeaderMatch()
```

## Methods

- `bind(scope: Construct): HeaderMatchConfig` — Returns the header match configuration.

- `valueDoesNotEndWith(headerName: string, suffix: string): HeaderMatch // chainable` (static) — The value of the header with the given name in the request must not end with the specified characters.

  **Parameters**

  - `headerName` — the name of the header to match against.
  - `suffix` — The suffix to test against.

- `valueDoesNotMatchRegex(headerName: string, regex: string): HeaderMatch // chainable` (static) — The value of the header with the given name in the request must not include the specified characters.

  **Parameters**

  - `headerName` — the name of the header to match against.
  - `regex` — The regex to test against.

- `valueDoesNotStartWith(headerName: string, prefix: string): HeaderMatch // chainable` (static) — The value of the header with the given name in the request must not start with the specified characters.

  **Parameters**

  - `headerName` — the name of the header to match against.
  - `prefix` — The prefix to test against.

- `valueEndsWith(headerName: string, suffix: string): HeaderMatch // chainable` (static) — The value of the header with the given name in the request must end with the specified characters.

  **Parameters**

  - `headerName` — the name of the header to match against.
  - `suffix` — The suffix to test against.

- `valueIs(headerName: string, headerValue: string): HeaderMatch // chainable` (static) — The value of the header with the given name in the request must match the specified value exactly.

  **Parameters**

  - `headerName` — the name of the header to match against.
  - `headerValue` — The exact value to test against.

- `valueIsNot(headerName: string, headerValue: string): HeaderMatch // chainable` (static) — The value of the header with the given name in the request must not match the specified value exactly.

  **Parameters**

  - `headerName` — the name of the header to match against.
  - `headerValue` — The exact value to test against.

- `valueMatchesRegex(headerName: string, regex: string): HeaderMatch // chainable` (static) — The value of the header with the given name in the request must include the specified characters.

  **Parameters**

  - `headerName` — the name of the header to match against.
  - `regex` — The regex to test against.

- `valuesIsInRange(headerName: string, start: number, end: number): HeaderMatch // chainable` (static) — The value of the header with the given name in the request must be in a range of values.

  **Parameters**

  - `headerName` — the name of the header to match against.
  - `start` — Match on values starting at and including this value.
  - `end` — Match on values up to but not including this value.

- `valuesIsNotInRange(headerName: string, start: number, end: number): HeaderMatch // chainable` (static) — The value of the header with the given name in the request must not be in a range of values.

  **Parameters**

  - `headerName` — the name of the header to match against.
  - `start` — Match on values starting at and including this value.
  - `end` — Match on values up to but not including this value.

- `valueStartsWith(headerName: string, prefix: string): HeaderMatch // chainable` (static) — The value of the header with the given name in the request must start with the specified characters.

  **Parameters**

  - `headerName` — the name of the header to match against.
  - `prefix` — The prefix to test against.
