Skip to content

Commit c3367a0

Browse files
committed
Use clearer replacement syntax
1 parent 1474d23 commit c3367a0

File tree

4 files changed

+15
-13
lines changed

4 files changed

+15
-13
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
test:
2-
go test -v ./...
2+
go test -v -failfast ./...
33

44
run:
55
go run main.go

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ Both requests will be proxied straight through to the specified upstream without
7070
Config{
7171
Path: `/(?P<cap>foo\w{3})`,
7272
Upstream: upstreams.HTTPBin,
73-
ModifyPath: "/anything/$cap",
73+
ModifyPath: "/anything/${cap}",
7474
}
7575
```
7676

@@ -94,7 +94,7 @@ Config{
9494
Override: Override{
9595
Header: "X-BF-Testing",
9696
Match: "integralist",
97-
ModifyPath: "/anything/newthing$cap",
97+
ModifyPath: "/anything/newthing${cap}",
9898
},
9999
}
100100
```
@@ -118,11 +118,11 @@ If the relevant request header is specified, then the request will be proxied th
118118
Config{
119119
Path: "/(?P<cap>double-checks)$",
120120
Upstream: upstreams.HTTPBin,
121-
ModifyPath: "/anything/toplevel-modified-$cap",
121+
ModifyPath: "/anything/toplevel-modified-${cap}",
122122
Override: Override{
123123
Header: "X-BF-Testing",
124124
Match: "integralist",
125-
ModifyPath: "/anything/override-modified-$cap",
125+
ModifyPath: "/anything/override-modified-${cap}",
126126
},
127127
}
128128
```
@@ -207,7 +207,7 @@ Config{
207207
Query: "s",
208208
Match: `integralist(?P<cap>\d{1,3})$`,
209209
MatchType: "regex",
210-
ModifyPath: "/anything/newthing$cap",
210+
ModifyPath: "/anything/newthing${cap}",
211211
},
212212
}
213213
```

proxy/proxy.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ func modifyPath(req *http.Request, modifyPath string) {
9797
if isCaptureGroup {
9898
// interpolate query param value into modified request path
9999
cleanKeyPrefix := strings.Replace(k, "ncg_", "", 1)
100-
r := strings.NewReplacer("$", "", cleanKeyPrefix, v[0])
100+
// replace ${foo} with foo
101+
r := strings.NewReplacer("$", "", "{", "", "}", "", cleanKeyPrefix, v[0])
101102
req.URL.Path = r.Replace(req.URL.Path)
102103
}
103104
}
@@ -122,7 +123,8 @@ func overrideHeader(req *http.Request, override routing.Override) {
122123
if isCaptureGroup {
123124
// interpolate query param value into modified request path
124125
cleanKeyPrefix := strings.Replace(k, "ncg_", "", 1)
125-
r := strings.NewReplacer("$", "", cleanKeyPrefix, v[0])
126+
// replace ${foo} with foo
127+
r := strings.NewReplacer("$", "", "{", "", "}", "", cleanKeyPrefix, v[0])
126128
req.URL.Path = r.Replace(req.URL.Path)
127129
}
128130
}

routing/configuration.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,17 @@ var Configuration = []Config{
3737
Override: Override{
3838
Header: "X-BF-Testing",
3939
Match: "integralist",
40-
ModifyPath: "/anything/newthing$cap",
40+
ModifyPath: "/anything/newthing${cap}",
4141
},
4242
},
4343
Config{
4444
Path: "/(?P<cap>double-checks)$",
4545
Upstream: upstreams.HTTPBin,
46-
ModifyPath: "/anything/toplevel-modified-$cap",
46+
ModifyPath: "/anything/toplevel-modified-${cap}",
4747
Override: Override{
4848
Header: "X-BF-Testing",
4949
Match: "integralist",
50-
ModifyPath: "/anything/override-modified-$cap",
50+
ModifyPath: "/anything/override-modified-${cap}",
5151
},
5252
},
5353
Config{
@@ -76,13 +76,13 @@ var Configuration = []Config{
7676
Query: "s",
7777
Match: `integralist(?P<cap>\d{1,3})$`,
7878
MatchType: "regex",
79-
ModifyPath: "/anything/newthing$cap",
79+
ModifyPath: "/anything/newthing${cap}",
8080
},
8181
},
8282
Config{
8383
Path: `/(?P<cap>foo\w{3})`,
8484
Upstream: upstreams.HTTPBin,
85-
ModifyPath: "/anything/$cap",
85+
ModifyPath: "/anything/${cap}",
8686
},
8787
Config{
8888
Path: "/beep(?P<cap>boop)",

0 commit comments

Comments
 (0)