Christopher Faulet | 1c22048 | 2020-09-03 11:53:50 +0200 | [diff] [blame] | 1 | varnishtest "path vs pathq tests" |
| 2 | #REQUIRE_VERSION=2.2 |
| 3 | |
| 4 | # This config tests various http request rules (set/replace) manipulating the |
| 5 | # path, with or without the query-string. It also test path and pathq sample |
| 6 | # fetches. |
| 7 | |
| 8 | feature ignore_unknown_macro |
| 9 | |
| 10 | server s1 { |
| 11 | rxreq |
| 12 | expect req.url == /regtest/foo/fe/req1/bar?param1=val1¶m2=val2 |
| 13 | expect req.http.x-path == /req1 |
| 14 | expect req.http.x-pathq == /req1?param1=val1¶m2=val2 |
| 15 | expect req.http.x-query == param1=val1¶m2=val2 |
| 16 | expect req.http.x-url == /req1?param1=val1¶m2=val2 |
| 17 | txresp |
| 18 | |
| 19 | rxreq |
| 20 | expect req.url == http://127.0.0.1/regtest/foo/fe/req2/bar?param1=val1¶m2=val2 |
| 21 | expect req.http.x-path == /req2 |
| 22 | expect req.http.x-pathq == /req2?param1=val1¶m2=val2 |
| 23 | expect req.http.x-query == param1=val1¶m2=val2 |
| 24 | expect req.http.x-url == http://127.0.0.1/req2?param1=val1¶m2=val2 |
| 25 | txresp |
| 26 | } -start |
| 27 | |
| 28 | haproxy h1 -conf { |
| 29 | defaults |
| 30 | mode http |
Willy Tarreau | f673923 | 2021-11-18 17:46:22 +0100 | [diff] [blame] | 31 | timeout connect "${HAPROXY_TEST_TIMEOUT-5s}" |
| 32 | timeout client "${HAPROXY_TEST_TIMEOUT-5s}" |
| 33 | timeout server "${HAPROXY_TEST_TIMEOUT-5s}" |
Christopher Faulet | 1c22048 | 2020-09-03 11:53:50 +0200 | [diff] [blame] | 34 | |
| 35 | frontend fe |
| 36 | bind "fd@${fe}" |
| 37 | |
| 38 | http-request add-header x-path %[path] |
| 39 | http-request add-header x-pathq %[pathq] |
| 40 | http-request add-header x-query %[query] |
| 41 | http-request add-header x-url %[url] |
| 42 | |
| 43 | http-request set-path /fe%[path] |
| 44 | http-request replace-path (.*) /foo\1 |
| 45 | http-request replace-path (.*) \1/bar |
| 46 | http-request set-pathq %[path]?app=regtest&%[query] |
| 47 | http-request replace-pathq /([^?]*)\?app=([^&]*)&?(.*) /\2/\1?\3 |
| 48 | |
| 49 | default_backend be |
| 50 | |
| 51 | backend be |
| 52 | server s1 ${s1_addr}:${s1_port} |
| 53 | |
| 54 | } -start |
| 55 | |
| 56 | client c1 -connect ${h1_fe_sock} { |
| 57 | txreq -req GET -url /req1?param1=val1¶m2=val2 |
| 58 | rxresp |
| 59 | expect resp.status == 200 |
| 60 | |
| 61 | txreq -req GET -url http://127.0.0.1/req2?param1=val1¶m2=val2 |
| 62 | rxresp |
| 63 | expect resp.status == 200 |
| 64 | } -run |