Frédéric Lécaille | 02a1669 | 2018-12-21 11:56:26 +0100 | [diff] [blame] | 1 | varnishtest "A test for http-request-buffer option" |
| 2 | feature ignore_unknown_macro |
| 3 | |
| 4 | #REQUIRE_VERSION=1.6 |
| 5 | |
| 6 | # This test checks HTTP request buffering feature. |
| 7 | # We run one server s1 which can serve only one client (no -repeat argument here). |
| 8 | # c1 client uses a malformed request which is not transferred to s1 server |
| 9 | # thanks to "http-buffer-request". If this was the case, c2 client |
| 10 | # could not connect to s1 server and this would lead to make this test fail. |
| 11 | |
| 12 | server s1 { |
| 13 | rxreq |
| 14 | expect req.bodylen == 257 |
| 15 | txresp |
Christopher Faulet | 58f21da | 2021-09-20 07:47:27 +0200 | [diff] [blame] | 16 | |
| 17 | accept |
| 18 | |
| 19 | rxreq |
| 20 | expect req.bodylen == 2 |
| 21 | txresp |
Frédéric Lécaille | 02a1669 | 2018-12-21 11:56:26 +0100 | [diff] [blame] | 22 | } -start |
| 23 | |
| 24 | syslog S -level info { |
| 25 | recv |
| 26 | expect ~ "[^:\\[ ]*\\[[0-9]*\\]: .* .* fe1 fe1/<NOSRV> .* 408 .* - - cD-- .* .* \"GET /this-is-a-long-url-this-is-a-long-url-this-is-a-long-url-this-is-a-long-url-this-is-a-long-url-this-is-a-long-url-this-is-a-long-url HTTP/1\\.1\"" |
| 27 | recv |
| 28 | expect ~ "[^:\\[ ]*\\[[0-9]*\\]: .* .* fe1 be1/srv1 [0-9]*/[0-9]*/[0-9]*/[0-9]*/[0-9]* 200 .* - - ---- .* .* \"GET / HTTP/1\\.1\"" |
Christopher Faulet | 58f21da | 2021-09-20 07:47:27 +0200 | [diff] [blame] | 29 | recv |
Christopher Faulet | dd259aa | 2022-06-02 14:01:30 +0200 | [diff] [blame^] | 30 | expect ~ "[^:\\[ ]*\\[[0-9]*\\]: .* .* fe2 be1/srv1 [0-9]*/[0-9]*/[0-9]*/[0-9]*/[0-9]* 200 .* - - ---- .* .* \"POST /1 HTTP/1\\.1\"" |
Christopher Faulet | 58f21da | 2021-09-20 07:47:27 +0200 | [diff] [blame] | 31 | recv |
Christopher Faulet | dd259aa | 2022-06-02 14:01:30 +0200 | [diff] [blame^] | 32 | expect ~ "[^:\\[ ]*\\[[0-9]*\\]: .* .* fe2 be1/<NOSRV> [0-9]*/-1/-1/-1/[0-9]* -1 .* - - CR-- .* .* \"POST /2 HTTP/1\\.1\"" |
Frédéric Lécaille | 02a1669 | 2018-12-21 11:56:26 +0100 | [diff] [blame] | 33 | } -start |
| 34 | |
| 35 | haproxy h1 -conf { |
| 36 | defaults |
| 37 | mode http |
| 38 | ${no-htx} option http-use-htx |
| 39 | timeout client 100ms |
| 40 | timeout server 1s |
| 41 | timeout connect 1s |
| 42 | |
| 43 | backend be1 |
| 44 | server srv1 ${s1_addr}:${s1_port} |
| 45 | |
| 46 | frontend fe1 |
| 47 | option httplog |
| 48 | option http-buffer-request |
| 49 | log ${S_addr}:${S_port} local0 debug err |
| 50 | bind "fd@${fe1}" |
| 51 | use_backend be1 |
Christopher Faulet | dd259aa | 2022-06-02 14:01:30 +0200 | [diff] [blame^] | 52 | |
| 53 | frontend fe2 |
| 54 | timeout client 10s |
| 55 | option httplog |
| 56 | option http-buffer-request |
| 57 | log ${S_addr}:${S_port} local0 debug err |
| 58 | bind "fd@${fe2}" |
| 59 | use_backend be1 |
Frédéric Lécaille | 02a1669 | 2018-12-21 11:56:26 +0100 | [diff] [blame] | 60 | } -start |
| 61 | |
Christopher Faulet | 58f21da | 2021-09-20 07:47:27 +0200 | [diff] [blame] | 62 | # 1 byte of the payload is missing. |
| 63 | # ==> The request must timed out with a 408 response |
Frédéric Lécaille | 02a1669 | 2018-12-21 11:56:26 +0100 | [diff] [blame] | 64 | client c1 -connect ${h1_fe1_sock} { |
| 65 | send "GET" |
| 66 | send " " |
| 67 | send "/this-is-a-long-url" |
| 68 | send "-this-is-a-long-url" |
| 69 | send "-this-is-a-long-url" |
| 70 | send "-this-is-a-long-url" |
| 71 | send "-this-is-a-long-url" |
| 72 | send "-this-is-a-long-url" |
| 73 | send "-this-is-a-long-url" |
| 74 | send " HTT" |
| 75 | send "P/1.1" |
| 76 | send "\r" |
| 77 | send "\n" |
| 78 | send "Content-Length: 209\r\n\r\n" |
| 79 | send "abcdefghijklmnopqrstuvwxyz" |
| 80 | send "abcdefghijklmnopqrstuvwxyz" |
| 81 | send "abcdefghijklmnopqrstuvwxyz" |
| 82 | send "abcdefghijklmnopqrstuvwxyz" |
| 83 | send "abcdefghijklmnopqrstuvwxyz" |
| 84 | send "abcdefghijklmnopqrstuvwxyz" |
| 85 | send "abcdefghijklmnopqrstuvwxyz" |
| 86 | send "abcdefghijklmnopqrstuvwxyz" |
| 87 | rxresp |
| 88 | expect resp.status == 408 |
| 89 | } -run |
| 90 | |
Christopher Faulet | 58f21da | 2021-09-20 07:47:27 +0200 | [diff] [blame] | 91 | # Payload is fully sent |
| 92 | # ==> Request must be sent to the server. A 200 must be received |
Frédéric Lécaille | 02a1669 | 2018-12-21 11:56:26 +0100 | [diff] [blame] | 93 | client c2 -connect ${h1_fe1_sock} { |
| 94 | txreq -bodylen 257 |
| 95 | rxresp |
| 96 | expect resp.status == 200 |
| 97 | } -run |
| 98 | |
Christopher Faulet | 58f21da | 2021-09-20 07:47:27 +0200 | [diff] [blame] | 99 | # Payload is fully sent in 2 steps (with a small delay, smaller than the client |
| 100 | # timeout) and splitted on a chunk size. |
| 101 | # ==> Request must be sent to the server. A 200 must be received |
Christopher Faulet | dd259aa | 2022-06-02 14:01:30 +0200 | [diff] [blame^] | 102 | client c3 -connect ${h1_fe2_sock} { |
Christopher Faulet | 58f21da | 2021-09-20 07:47:27 +0200 | [diff] [blame] | 103 | send "POST /1 HTTP/1.1\r\nTransfer-Encoding: chunked\r\n\r\n1\r\n1\r\n1" |
| 104 | delay 0.01 |
| 105 | send "\r\n1\r\n0\r\n\r\n" |
| 106 | rxresp |
| 107 | expect resp.status == 200 |
| 108 | } -run |
Frédéric Lécaille | 02a1669 | 2018-12-21 11:56:26 +0100 | [diff] [blame] | 109 | |
Christopher Faulet | 58f21da | 2021-09-20 07:47:27 +0200 | [diff] [blame] | 110 | # Last CRLF of the request payload is missing but payload is sent in 2 steps |
| 111 | # (with a small delay, smaller than the client timeout) and splitted on a chunk |
| 112 | # size. The client aborts before sending the last CRLF. |
| 113 | # ==> Request must be handled as an error with 'CR--' termination state. |
Christopher Faulet | dd259aa | 2022-06-02 14:01:30 +0200 | [diff] [blame^] | 114 | client c4 -connect ${h1_fe2_sock} { |
Christopher Faulet | 58f21da | 2021-09-20 07:47:27 +0200 | [diff] [blame] | 115 | send "POST /2 HTTP/1.1\r\nTransfer-Encoding: chunked\r\n\r\n1\r\n1\r\n1" |
| 116 | delay 0.01 |
| 117 | send "\r\n1\r\n0\r\n" |
| 118 | } -run |
| 119 | |
| 120 | syslog S -wait |