Aurelien DARRAGON | 424981c | 2023-01-09 11:02:48 +0100 | [diff] [blame] | 1 | varnishtest "Test if-none param for the forwardfor option" |
| 2 | #REQUIRE_VERSION=2.6 |
| 3 | |
| 4 | # This config tests the if-none parameter for the HTTP forwardfor option. |
| 5 | |
| 6 | feature ignore_unknown_macro |
| 7 | |
| 8 | haproxy h1 -conf { |
| 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 | |
| 15 | defaults |
| 16 | mode http |
| 17 | timeout connect "${HAPROXY_TEST_TIMEOUT-5s}" |
| 18 | timeout client "${HAPROXY_TEST_TIMEOUT-5s}" |
| 19 | timeout server "${HAPROXY_TEST_TIMEOUT-5s}" |
| 20 | |
| 21 | frontend none |
| 22 | bind "fd@${none}" |
| 23 | http-request set-src hdr(x-src) |
| 24 | option forwardfor if-none |
| 25 | use_backend be1 if { path /req1 } |
| 26 | use_backend be2 if { path /req2 } |
| 27 | |
| 28 | frontend normal |
| 29 | bind "fd@${normal}" |
| 30 | http-request set-src hdr(x-src) |
| 31 | option forwardfor |
| 32 | use_backend be1 if { path /req1 } |
| 33 | use_backend be2 if { path /req2 } |
| 34 | |
| 35 | |
| 36 | frontend fe2 |
| 37 | bind "fd@${fe2}" |
| 38 | http-request return status 200 hdr x-ff "%[req.fhdr_cnt(x-forwarded-for)]" |
| 39 | |
| 40 | backend be1 |
| 41 | option forwardfor |
| 42 | server s1 ${h1_fe2_addr}:${h1_fe2_port} |
| 43 | |
| 44 | backend be2 |
| 45 | option forwardfor if-none |
| 46 | server s1 ${h1_fe2_addr}:${h1_fe2_port} |
| 47 | } -start |
| 48 | |
| 49 | client c1 -connect ${h1_none_sock} { |
| 50 | txreq -req GET -url /req1 \ |
| 51 | -hdr "x-src: 10.0.0.128" \ |
| 52 | -hdr "x-forwarded-for: 127.0.0.1" |
| 53 | rxresp |
| 54 | expect resp.status == 200 |
| 55 | expect resp.http.x-ff == 2 |
| 56 | |
| 57 | txreq -req GET -url /req2 \ |
| 58 | -hdr "x-src: 10.0.0.128" \ |
| 59 | -hdr "x-forwarded-for: 127.0.0.1" |
| 60 | rxresp |
| 61 | expect resp.status == 200 |
| 62 | expect resp.http.x-ff == 1 |
| 63 | |
| 64 | txreq -req GET -url /req2 \ |
| 65 | -hdr "x-src: 10.0.0.128" |
| 66 | rxresp |
| 67 | expect resp.status == 200 |
| 68 | expect resp.http.x-ff == 1 |
| 69 | |
| 70 | } -run |
| 71 | |
| 72 | client c1 -connect ${h1_normal_sock} { |
| 73 | txreq -req GET -url /req1 \ |
| 74 | -hdr "x-src: 10.0.0.128" \ |
| 75 | -hdr "x-forwarded-for: 127.0.0.1" |
| 76 | rxresp |
| 77 | expect resp.status == 200 |
| 78 | expect resp.http.x-ff == 2 |
| 79 | |
| 80 | txreq -req GET -url /req2 \ |
| 81 | -hdr "x-src: 10.0.0.128" \ |
| 82 | -hdr "x-forwarded-for: 127.0.0.1" |
| 83 | rxresp |
| 84 | expect resp.status == 200 |
| 85 | expect resp.http.x-ff == 2 |
| 86 | |
| 87 | } -run |