-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathurl-rewriting.yaml
More file actions
73 lines (69 loc) · 1.99 KB
/
url-rewriting.yaml
File metadata and controls
73 lines (69 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# URL Rewriting
#
# Regex-based path transformation and query string manipulation.
#
# Operations execute in declared order:
#
# /v1/users?debug=true&trace=1
# |
# v
# +-------------------------+
# | regex_replace | /v1/users -> /v2/users
# +-------------------------+
# |
# v
# +-------------------------+
# | strip_query_params | ?debug=true&trace=1 -> (empty)
# +-------------------------+
# |
# v
# +-------------------------+
# | add_query_params | -> ?source=gateway
# +-------------------------+
# |
# v
# /v2/users?source=gateway
#
# Usage:
# cargo run -p praxis -- -c examples/configs/transformation/url-rewriting.yaml
# curl http://localhost:8080/v1/users?debug=true
# # Request reaches backend as /v2/users?source=gateway
#
# NOTE: The router checks rewritten_path before the original
# URI, so "rewrite then route" pipelines work: place a rewrite
# filter before the router and the router will match against
# the rewritten path.
#
# If both path_rewrite and url_rewrite appear in the same
# pipeline, only the last one's rewrite takes effect.
# Validation rejects this by default; set
# allow_rewrite_override: true on the later filter to permit
# it. Security consideration: filter order matters; the last
# rewrite wins, so misordering can bypass path-based ACLs.
listeners:
- name: default
address: "127.0.0.1:8080"
filter_chains:
- main
filter_chains:
- name: main
filters:
- filter: url_rewrite
operations:
- regex_replace:
pattern: "^/v1/(.*)"
replacement: "/v2/$1"
- strip_query_params:
- debug
- trace
- add_query_params:
source: gateway
- filter: router
routes:
- path_prefix: "/"
cluster: backend
- filter: load_balancer
clusters:
- name: backend
endpoints:
- "127.0.0.1:3000"