Skip to content

Commit 150ea9d

Browse files
committed
BUG/MINOR: fix the http-request set-uri serialization
The API was using "hdr_format" instead "uri-fmt".
1 parent 389b6b5 commit 150ea9d

File tree

4 files changed

+21
-5
lines changed

4 files changed

+21
-5
lines changed

configuration/http_request_rule.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -678,10 +678,10 @@ func ParseHTTPRequestRule(f types.Action) (*models.HTTPRequestRule, error) { //n
678678
}
679679
case *http_actions.SetURI:
680680
rule = &models.HTTPRequestRule{
681-
Type: "set-uri",
682-
HdrFormat: v.Fmt,
683-
Cond: v.Cond,
684-
CondTest: v.CondTest,
681+
Type: "set-uri",
682+
URIFmt: v.Fmt,
683+
Cond: v.Cond,
684+
CondTest: v.CondTest,
685685
}
686686
case *actions.SetVar:
687687
rule = &models.HTTPRequestRule{
@@ -1196,7 +1196,7 @@ func SerializeHTTPRequestRule(f models.HTTPRequestRule, opt *options.Configurati
11961196
}
11971197
case "set-uri":
11981198
rule = &http_actions.SetURI{
1199-
Fmt: f.HdrFormat,
1199+
Fmt: f.URIFmt,
12001200
Cond: f.Cond,
12011201
CondTest: f.CondTest,
12021202
}

test/configuration_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,7 @@ backend test
781781
server webserv2 192.168.1.1:9300 maxconn 1000 ssl weight 10 inter 2s cookie BLAH slowstart 6000 proxy-v2-options authority,crc32c ws h1 pool-low-conn 128 hash-key akey pool-conn-name apoolconnname # {"comment": "my structured comment", "id": "my_random_id_for_server"}
782782
http-request set-dst hdr(x-dst)
783783
http-request set-dst-port int(4000)
784+
http-request set-uri %[url,regsub(^/metrics/,/,)] if { path_beg /metrics }
784785
http-check connect
785786
http-check send meth GET uri / ver HTTP/1.1 hdr host haproxy.1wt.eu
786787
http-check expect status 200-399

test/expected/structured.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,12 @@
721721
{
722722
"expr": "int(4000)",
723723
"type": "set-dst-port"
724+
},
725+
{
726+
"type": "set-uri",
727+
"uri-fmt": "%[url,regsub(^/metrics/,/,)]",
728+
"cond": "if",
729+
"cond_test": "{ path_beg /metrics }"
724730
}
725731
],
726732
"http_response_rule_list": [

test/http_request_rule_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,15 @@ func TestSerializeHTTPRequestRule(t *testing.T) {
232232
},
233233
expectedResult: "track-sc3 src table tr0 if TRUE",
234234
},
235+
{
236+
input: models.HTTPRequestRule{
237+
Type: "set-uri",
238+
Cond: "if",
239+
CondTest: "{ path_beg /metrics }",
240+
URIFmt: "%[url,regsub(^/metrics/,/,)]",
241+
},
242+
expectedResult: "set-uri %[url,regsub(^/metrics/,/,)] if { path_beg /metrics }",
243+
},
235244
}
236245

237246
for _, testCase := range testCases {

0 commit comments

Comments
 (0)