Remi Tricot-Le Breton | a647611 | 2020-10-28 17:52:53 +0100 | [diff] [blame] | 1 | varnishtest "Expires support" |
| 2 | |
| 3 | #REQUIRE_VERSION=2.3 |
| 4 | |
| 5 | feature ignore_unknown_macro |
| 6 | |
| 7 | server s1 { |
| 8 | rxreq |
| 9 | txresp -nolen -hdr "Transfer-Encoding: chunked" \ |
| 10 | -hdr "Cache-Control: max-age=5" |
| 11 | chunkedlen 15 |
| 12 | chunkedlen 15 |
| 13 | chunkedlen 15 |
| 14 | chunkedlen 0 |
| 15 | } -start |
| 16 | |
| 17 | server s2 { |
| 18 | rxreq |
| 19 | txresp -nolen -hdr "Transfer-Encoding: chunked" |
| 20 | chunkedlen 16 |
| 21 | chunkedlen 16 |
| 22 | chunkedlen 16 |
| 23 | chunkedlen 0 |
| 24 | } -start |
| 25 | |
| 26 | server s3 { |
| 27 | rxreq |
| 28 | txresp -nolen -hdr "Transfer-Encoding: chunked" |
| 29 | chunkedlen 16 |
| 30 | chunkedlen 16 |
| 31 | chunkedlen 16 |
| 32 | chunkedlen 0 |
| 33 | |
| 34 | rxreq |
| 35 | txresp -nolen -hdr "Transfer-Encoding: chunked" |
| 36 | chunkedlen 17 |
| 37 | chunkedlen 17 |
| 38 | chunkedlen 17 |
| 39 | chunkedlen 0 |
| 40 | } -start |
| 41 | |
| 42 | haproxy h1 -conf { |
Willy Tarreau | e1465c1 | 2021-05-09 14:41:41 +0200 | [diff] [blame] | 43 | global |
| 44 | # WT: limit false-positives causing "HTTP header incomplete" due to |
| 45 | # idle server connections being randomly used and randomly expiring |
| 46 | # under us. |
| 47 | tune.idle-pool.shared off |
| 48 | |
Remi Tricot-Le Breton | a647611 | 2020-10-28 17:52:53 +0100 | [diff] [blame] | 49 | defaults |
| 50 | mode http |
| 51 | ${no-htx} option http-use-htx |
| 52 | timeout connect 1s |
| 53 | timeout client 1s |
| 54 | timeout server 1s |
| 55 | |
| 56 | frontend fe |
| 57 | bind "fd@${fe}" |
| 58 | use_backend cache_control_be if { path_beg /cache_control } |
| 59 | use_backend future_expires_be if { path_beg /future } |
| 60 | default_backend past_expires_be |
| 61 | |
| 62 | backend cache_control_be |
| 63 | # Expires header should be ignored since a Cache-Control one is present |
| 64 | http-request cache-use my_cache |
| 65 | server www ${s1_addr}:${s1_port} |
| 66 | http-response set-header X-Cache-Hit %[res.cache_hit] |
| 67 | http-response set-header Expires %[date(-1),http_date] |
| 68 | http-response cache-store my_cache |
| 69 | |
| 70 | backend future_expires_be |
| 71 | # Expires value set in the future (current_time+5s) |
| 72 | http-request cache-use my_cache |
| 73 | server www ${s2_addr}:${s2_port} |
| 74 | http-response set-header X-Cache-Hit %[res.cache_hit] |
| 75 | http-response set-header Expires %[date(5),http_date] |
| 76 | http-response cache-store my_cache |
| 77 | |
| 78 | backend past_expires_be |
| 79 | # Expires value set in the past |
| 80 | http-request cache-use my_cache |
| 81 | server www ${s3_addr}:${s3_port} |
| 82 | http-response set-header X-Cache-Hit %[res.cache_hit] |
| 83 | http-response set-header Expires %[date(-1),http_date] |
| 84 | http-response cache-store my_cache |
| 85 | |
| 86 | cache my_cache |
| 87 | total-max-size 3 |
| 88 | max-age 20 |
| 89 | max-object-size 3072 |
| 90 | } -start |
| 91 | |
| 92 | |
| 93 | client c1 -connect ${h1_fe_sock} { |
| 94 | txreq -url "/cache_control" |
| 95 | rxresp |
| 96 | expect resp.status == 200 |
| 97 | expect resp.bodylen == 45 |
| 98 | |
| 99 | txreq -url "/cache_control" |
| 100 | rxresp |
| 101 | expect resp.status == 200 |
| 102 | expect resp.bodylen == 45 |
| 103 | expect resp.http.X-Cache-Hit == 1 |
| 104 | |
| 105 | txreq -url "/future" |
| 106 | rxresp |
| 107 | expect resp.status == 200 |
| 108 | expect resp.bodylen == 48 |
| 109 | |
| 110 | txreq -url "/future" |
| 111 | rxresp |
| 112 | expect resp.status == 200 |
| 113 | expect resp.bodylen == 48 |
| 114 | expect resp.http.X-Cache-Hit == 1 |
| 115 | |
| 116 | txreq -url "/past" |
| 117 | rxresp |
| 118 | expect resp.status == 200 |
| 119 | expect resp.bodylen == 48 |
| 120 | |
| 121 | txreq -url "/past" |
| 122 | rxresp |
| 123 | expect resp.status == 200 |
| 124 | expect resp.bodylen == 51 |
| 125 | expect resp.http.X-Cache-Hit == 0 |
| 126 | |
| 127 | } -run |
| 128 | |