-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #596 from sgayangi/sgayangi-httproute-filters
Add documentation for HTTPRoute filters
- Loading branch information
Showing
12 changed files
with
890 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
We support API management through a set of Custom Resources (CRs) that adhere to Kubernetes Gateway Specification. See [APK Kubernetes CRD Catalog]({{base_path}}/en/latest/catalogs/kubernetes-crds) for more information. | ||
|
||
Additionally, our REST API flow can generate a set of CRs based on the API definitions provided through OpenAPI Specifications, Service Description Languages (SDLs), and APK configuration files. This flow is designed to streamline the API development process and reduce the manual effort required to create basic API related CRs. Follow steps mentions in [Generate APK Configuration File]({{base_path}}/en/latest/api-management-overview/tools-for-api-development/#option-2-generate-k8s-custom-resources-using-config-generator-tool-and-deploy-the-api-using-kubernetes-client) to generate APK configuration files. | ||
Additionally, our REST API flow can generate a set of CRs based on the API definitions provided through OpenAPI Specifications, Service Description Languages (SDLs), and APK configuration files. This flow is designed to streamline the API development process and reduce the manual effort required to create basic API related CRs. Follow the steps mentioned in [Generate APK Configuration File]({{base_path}}/en/latest/api-management-overview/tools-for-api-development/#option-2-generate-k8s-custom-resources-using-config-generator-tool-and-deploy-the-api-using-kubernetes-client) to generate APK configuration files. |
Binary file added
BIN
+325 KB
en/docs/assets/img/api-management/api-policies/webhook-site-request-mirroring.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
191 changes: 191 additions & 0 deletions
191
...eate-and-attach-api-policies/header-modifier-filters/header-modifier-via-crs.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,191 @@ | ||
# Header Modification via CRs | ||
|
||
This functionality enables the addition, modification, and removal of request and response headers for APIs. By customizing headers, you can enhance the control and flexibility of API interactions, ensuring that both incoming requests and outgoing responses meet specific requirements. | ||
|
||
### Step 1 - Get the CRs for the relevant API configuration | ||
|
||
Here, you can follow the steps in [Develop and Deploy a REST API via CRs](../../create-and-deploy-apis/rest/create-rest-api-using-crs.md) documentation and create the CRs to deploy an API from scratch. | ||
|
||
Alternatively, you can generate the CRs for a given apk-conf file using the steps as detailed in [this section]({{base_path}}/en/latest/api-management-overview/tools-for-api-development/#option-2-generate-k8s-custom-resources-using-config-generator-tool-and-deploy-the-api-using-kubernetes-client) | ||
|
||
### Step 2 - Add the header modification filters to the HTTPRoute CR | ||
|
||
Header modification can be done using an HTTPRoute filter as follows. | ||
|
||
``` | ||
- type: "RequestHeaderModifier" | ||
requestHeaderModifier: | ||
set: | ||
- name: "Set-Request-Header" | ||
value: "Set-Value" | ||
add: | ||
- name: "Add-Request-Header" | ||
value: "Added-Value" | ||
remove: | ||
- "Remove-Request-Header" | ||
``` | ||
|
||
This filter does the following modifications to the request headers. | ||
|
||
1. Update the header named "Set-Request-Header" with the value "Set-Value". | ||
2. Adds a header named "Add-Request-Header" with the value "Added-Value". | ||
3. Removes the header named "Remove-Request-Header". | ||
|
||
!!! Note | ||
- By replacing the type with "ResponseHeaderModifier", the modifications can be done to the response. | ||
- Both RequestHeaderModifier and ResponseHeaderModifier can be added to the same rule. | ||
|
||
An HTTPRoute with the header modifiers is given below. | ||
|
||
``` | ||
--- | ||
apiVersion: "gateway.networking.k8s.io/v1beta1" | ||
kind: "HTTPRoute" | ||
metadata: | ||
name: "production-httproute" | ||
spec: | ||
hostnames: | ||
- "default.gw.wso2.com" | ||
rules: | ||
- matches: | ||
- path: | ||
type: "RegularExpression" | ||
value: "/employee" | ||
method: "GET" | ||
filters: | ||
- type: "URLRewrite" | ||
urlRewrite: | ||
path: | ||
type: "ReplaceFullPath" | ||
replaceFullPath: "/employee" | ||
- type: "RequestHeaderModifier" | ||
requestHeaderModifier: | ||
set: | ||
- name: "Set-Request-Header" | ||
value: "Test-Value" | ||
add: | ||
- name: "Test-Request-Header" | ||
value: "Test-Value" | ||
remove: | ||
- "Remove-Header" | ||
backendRefs: | ||
- group: "dp.wso2.com" | ||
kind: "Backend" | ||
name: "api-backend" | ||
``` | ||
|
||
Sample configurations for each of them have been provided under the [Sample Configurations](#sample-configurations) section. | ||
|
||
### Step 3 - Deploy the API in APK | ||
You can deploy the API using the following command. Replace <namespace> with the correct namespace. | ||
``` | ||
kubectl apply -f . -n <namespace> | ||
``` | ||
|
||
### Sample Configurations | ||
|
||
#### Request Header Modification | ||
|
||
##### 1. Add Request Header | ||
|
||
``` | ||
rules: | ||
- matches: | ||
- path: | ||
type: "RegularExpression" | ||
value: "/employee" | ||
method: "GET" | ||
filters: | ||
- type: "RequestHeaderModifier" | ||
requestHeaderModifier: | ||
add: | ||
- name: "Add-Request-Header" | ||
value: "Added-Value" | ||
``` | ||
|
||
##### 2. Update Request Header | ||
|
||
``` | ||
rules: | ||
- matches: | ||
- path: | ||
type: "RegularExpression" | ||
value: "/employee" | ||
method: "GET" | ||
filters: | ||
- type: "RequestHeaderModifier" | ||
requestHeaderModifier: | ||
add: | ||
- name: "Set-Request-Header" | ||
value: "Set-Value" | ||
``` | ||
|
||
##### 3. Remove Request Header | ||
|
||
``` | ||
rules: | ||
- matches: | ||
- path: | ||
type: "RegularExpression" | ||
value: "/employee" | ||
method: "GET" | ||
filters: | ||
- type: "RequestHeaderModifier" | ||
requestHeaderModifier: | ||
add: | ||
- name: "Add-Request-Header" | ||
value: "Added-Value" | ||
``` | ||
|
||
#### Response Header Modification | ||
|
||
##### 1. Add Request Header | ||
|
||
``` | ||
rules: | ||
- matches: | ||
- path: | ||
type: "RegularExpression" | ||
value: "/employee" | ||
method: "GET" | ||
filters: | ||
- type: "ResponseHeaderModifier" | ||
requestHeaderModifier: | ||
add: | ||
- name: "Add-Request-Header" | ||
value: "Added-Value" | ||
``` | ||
|
||
##### 2. Update Request Header | ||
|
||
``` | ||
rules: | ||
- matches: | ||
- path: | ||
type: "RegularExpression" | ||
value: "/employee" | ||
method: "GET" | ||
filters: | ||
- type: "ResponseHeaderModifier" | ||
requestHeaderModifier: | ||
add: | ||
- name: "Set-Request-Header" | ||
value: "Set-Value" | ||
``` | ||
|
||
##### 3. Remove Response Header | ||
|
||
``` | ||
rules: | ||
- matches: | ||
- path: | ||
type: "RegularExpression" | ||
value: "/employee" | ||
method: "GET" | ||
filters: | ||
- type: "ResponseHeaderModifier" | ||
requestHeaderModifier: | ||
add: | ||
- name: "Add-Request-Header" | ||
value: "Added-Value" | ||
``` |
Oops, something went wrong.