Christopher Faulet | c5a0aee | 2020-02-05 16:46:38 +0100 | [diff] [blame] | 1 | varnishtest "Test the HTTP return action" |
| 2 | #REQUIRE_VERSION=2.2 |
| 3 | |
| 4 | # This config tests the HTTP return action. |
| 5 | |
| 6 | feature ignore_unknown_macro |
| 7 | |
| 8 | haproxy h1 -conf { |
Willy Tarreau | e1465c1 | 2021-05-09 14:41:41 +0200 | [diff] [blame] | 9 | global |
| 10 | # WT: limit false-positives causing "HTTP header incomplete" due to |
| 11 | # idle server connections being randomly used and randomly expiring |
| 12 | # under us. |
| 13 | tune.idle-pool.shared off |
| 14 | |
Christopher Faulet | c5a0aee | 2020-02-05 16:46:38 +0100 | [diff] [blame] | 15 | defaults |
| 16 | mode http |
| 17 | timeout connect 1s |
| 18 | timeout client 1s |
| 19 | timeout server 1s |
| 20 | |
| 21 | frontend fe1 |
| 22 | bind "fd@${fe1}" |
| 23 | http-request return if { path /def-1 } |
| 24 | http-request return hdr "x-custom-hdr" "%[url]" if { path /def-2 } |
| 25 | http-request return status 403 if { path /def-3 } |
| 26 | http-request return content-type "text/plain" if { path /def-4 } |
| 27 | |
| 28 | http-request return content-type "text/plain" string "hello" hdr "x-custom-hdr" "%[url]" if { path /string } |
| 29 | http-request return content-type "text/plain" lf-string "path is %[url]" hdr "x-custom-hdr" "%[url]" if { path /lf-string } |
| 30 | http-request return content-type "text/plain" file /dev/null hdr "x-custom-hdr" "%[url]" if { path /empty-file } |
| 31 | http-request return content-type "text/plain" file ${testdir}/1k.txt hdr "x-custom-hdr" "%[url]" if { path /file } |
| 32 | http-request return content-type "text/plain" lf-file ${testdir}/lf-file.txt hdr "x-custom-hdr" "%[url]" if { path /lf-file } |
| 33 | } -start |
| 34 | |
| 35 | client c1 -connect ${h1_fe1_sock} { |
| 36 | txreq -req GET -url /def-1 |
| 37 | rxresp |
| 38 | expect resp.status == 200 |
| 39 | expect resp.http.content-length == 0 |
| 40 | expect resp.http.content-type == <undef> |
| 41 | expect resp.http.x-custom-hdr == <undef> |
| 42 | |
| 43 | txreq -req GET -url /def-2 |
| 44 | rxresp |
| 45 | expect resp.status == 200 |
| 46 | expect resp.http.content-length == 0 |
| 47 | expect resp.http.content-type == <undef> |
| 48 | expect resp.http.x-custom-hdr == "/def-2" |
| 49 | |
| 50 | txreq -req GET -url /def-3 |
| 51 | rxresp |
| 52 | expect resp.status == 403 |
| 53 | expect resp.http.content-length == 0 |
| 54 | expect resp.http.content-type == <undef> |
| 55 | |
| 56 | txreq -req GET -url /def-4 |
| 57 | rxresp |
| 58 | expect resp.status == 200 |
| 59 | expect resp.http.content-length == 0 |
| 60 | expect resp.http.content-type == <undef> |
| 61 | |
| 62 | txreq -req GET -url /string |
| 63 | rxresp |
| 64 | expect resp.status == 200 |
| 65 | expect resp.http.content-length == 5 |
| 66 | expect resp.http.content-type == "text/plain" |
| 67 | expect resp.http.x-custom-hdr == "/string" |
| 68 | expect resp.body == "hello" |
| 69 | |
| 70 | txreq -req GET -url /lf-string |
| 71 | rxresp |
| 72 | expect resp.status == 200 |
| 73 | expect resp.http.content-length == 18 |
| 74 | expect resp.http.content-type == "text/plain" |
| 75 | expect resp.http.x-custom-hdr == "/lf-string" |
| 76 | expect resp.body == "path is /lf-string" |
| 77 | |
| 78 | txreq -req GET -url /empty-file |
| 79 | rxresp |
| 80 | expect resp.status == 200 |
| 81 | expect resp.http.content-length == 0 |
| 82 | expect resp.http.content-type == <undef> |
| 83 | expect resp.http.x-custom-hdr == "/empty-file" |
| 84 | |
| 85 | txreq -req GET -url /file |
| 86 | rxresp |
| 87 | expect resp.status == 200 |
| 88 | expect resp.http.content-length == 1024 |
| 89 | expect resp.http.content-type == "text/plain" |
| 90 | expect resp.http.x-custom-hdr == "/file" |
| 91 | |
| 92 | txreq -req GET -url /lf-file |
| 93 | rxresp |
| 94 | expect resp.status == 200 |
| 95 | expect resp.http.content-length == 17 |
| 96 | expect resp.http.content-type == "text/plain" |
| 97 | expect resp.http.x-custom-hdr == "/lf-file" |
| 98 | expect resp.body == "path is /lf-file\n" |
| 99 | } -run |