Skip to content

Commit

Permalink
Added usage example of filter "header-modifier"、"url-rewrite". (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
wanpf authored Oct 12, 2023
1 parent 2a444ce commit ff73ce5
Show file tree
Hide file tree
Showing 5 changed files with 365 additions and 24 deletions.
14 changes: 7 additions & 7 deletions pjs/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,16 @@
"http/access-log.js",
"http/auth.js",
"http/route.js",
"filter/request-redirect.js",
"filter/header-modifier.js",
"filter/url-rewrite.js",
"http/service.js",
"http/metrics.js",
"http/tracing.js",
"http/logging.js",
"http/circuit-breaker.js",
"http/throttle-domain.js",
"http/throttle-route.js",
"filter/request-redirect.js",
"filter/header-modifier.js",
"filter/url-rewrite.js",
"http/error-page.js",
"http/proxy-redirect.js",
"http/forward.js",
Expand All @@ -156,16 +156,16 @@
"http/access-log.js",
"http/auth.js",
"http/route.js",
"filter/request-redirect.js",
"filter/header-modifier.js",
"filter/url-rewrite.js",
"http/service.js",
"http/metrics.js",
"http/tracing.js",
"http/logging.js",
"http/circuit-breaker.js",
"http/throttle-domain.js",
"http/throttle-route.js",
"filter/request-redirect.js",
"filter/header-modifier.js",
"filter/url-rewrite.js",
"http/error-page.js",
"http/proxy-redirect.js",
"http/forward.js",
Expand All @@ -191,4 +191,4 @@
]
},
"Version": "0"
}
}
4 changes: 3 additions & 1 deletion pjs/filter/header-modifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
content = _http?.headers?.[member] || _http?.[member] || val
) || (name === 'consumer') && (
content = __consumer?.[member] || val
) || (name === 'inbound') && (
content = __inbound?.[member] || val
)
),
content
Expand Down Expand Up @@ -183,4 +185,4 @@
)
)

)()
)()
183 changes: 183 additions & 0 deletions pjs/samples/header-modifier/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
{
"Configs": {
"EnableDebug": true
},
"Listeners": [
{
"Protocol": "HTTP",
"Port": 8080
},
{
"Protocol": "HTTP",
"Port": 8081
},
{
"Protocol": "HTTP",
"Port": 8082
}
],
"RouteRules": {
"8080": {
"*": {
"RouteType": "HTTP",
"Matches": [
{
"Path": {
"Type": "Prefix",
"Path": "/"
},
"Filters": [
{
"Type": "RequestHeaderModifier",
"RequestHeaderModifier": {
"Set": [
{
"Name": "Proxy",
"Value": "fgw"
}
],
"Add": [
{
"Name": "user-agent",
"Value": "$inbound_localAddress"
}
],
"Remove": [
"accept"
]
}
},
{
"Type": "ResponseHeaderModifier",
"ResponseHeaderModifier": {
"Set": [
{
"Name": "Server",
"Value": "fgw"
}
]
}
}
],
"BackendService": {
"backendService1": {
"Weight": 100
}
}
}
]
}
},
"8081": {
"*": {
"Matches": [
{
"ServerRoot": "/var/www/html",
"Index": [
"index.html",
"index.htm"
],
"TryFiles": [
"$uri",
"$uri/default/",
"=404"
]
}
]
}
},
"8082": {
"*": {
"Matches": [
{
"ServerRoot": "www2",
"Index": [
"default.html",
"index.html"
]
}
]
}
}
},
"Services": {
"backendService1": {
"Endpoints": {
"127.0.0.1:8081": {
"Weight": 50
},
"127.0.0.1:8082": {
"Weight": 50
}
}
}
},
"Chains": {
"HTTPRoute": [
"common/access-control.js",
"common/ratelimit.js",
"common/consumer.js",
"http/codec.js",
"http/access-log.js",
"http/auth.js",
"http/route.js",
"filter/request-redirect.js",
"filter/header-modifier.js",
"filter/url-rewrite.js",
"http/service.js",
"http/metrics.js",
"http/tracing.js",
"http/logging.js",
"http/circuit-breaker.js",
"http/throttle-domain.js",
"http/throttle-route.js",
"http/error-page.js",
"http/proxy-redirect.js",
"http/forward.js",
"http/default.js"
],
"HTTPSRoute": [
"common/access-control.js",
"common/ratelimit.js",
"common/tls-termination.js",
"common/consumer.js",
"http/codec.js",
"http/access-log.js",
"http/auth.js",
"http/route.js",
"filter/request-redirect.js",
"filter/header-modifier.js",
"filter/url-rewrite.js",
"http/service.js",
"http/metrics.js",
"http/tracing.js",
"http/logging.js",
"http/circuit-breaker.js",
"http/throttle-domain.js",
"http/throttle-route.js",
"http/error-page.js",
"http/proxy-redirect.js",
"http/forward.js",
"http/default.js"
],
"TLSPassthrough": [
"common/access-control.js",
"common/ratelimit.js",
"tls/passthrough.js",
"common/consumer.js"
],
"TLSTerminate": [
"common/access-control.js",
"common/ratelimit.js",
"common/tls-termination.js",
"common/consumer.js",
"tls/forward.js"
],
"TCPRoute": [
"common/access-control.js",
"common/ratelimit.js",
"tcp/forward.js"
]
},
"Version": "0"
}
25 changes: 9 additions & 16 deletions pjs/samples/request-redirect/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,13 @@
"StatusCode": 301
}
}
],
"BackendService": {
"emptyService": {
"Weight": 100
}
}
]
}
]
}
}
},
"Services": {
"emptyService": {}
},
"Services": {},
"Chains": {
"HTTPRoute": [
"common/access-control.js",
Expand All @@ -48,16 +41,16 @@
"http/access-log.js",
"http/auth.js",
"http/route.js",
"filter/request-redirect.js",
"filter/header-modifier.js",
"filter/url-rewrite.js",
"http/service.js",
"http/metrics.js",
"http/tracing.js",
"http/logging.js",
"http/circuit-breaker.js",
"http/throttle-domain.js",
"http/throttle-route.js",
"filter/request-redirect.js",
"filter/header-modifier.js",
"filter/url-rewrite.js",
"http/error-page.js",
"http/proxy-redirect.js",
"http/forward.js",
Expand All @@ -72,16 +65,16 @@
"http/access-log.js",
"http/auth.js",
"http/route.js",
"filter/request-redirect.js",
"filter/header-modifier.js",
"filter/url-rewrite.js",
"http/service.js",
"http/metrics.js",
"http/tracing.js",
"http/logging.js",
"http/circuit-breaker.js",
"http/throttle-domain.js",
"http/throttle-route.js",
"filter/request-redirect.js",
"filter/header-modifier.js",
"filter/url-rewrite.js",
"http/error-page.js",
"http/proxy-redirect.js",
"http/forward.js",
Expand All @@ -107,4 +100,4 @@
]
},
"Version": "0"
}
}
Loading

0 comments on commit ff73ce5

Please sign in to comment.