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