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 |
| 30 | expect ~ "[^:\\[ ]*\\[[0-9]*\\]: .* .* fe1 be1/srv1 [0-9]*/[0-9]*/[0-9]*/[0-9]*/[0-9]* 200 .* - - ---- .* .* \"POST /1 HTTP/1\\.1\"" |
| 31 | recv |
| 32 | 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] | 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 |
| 52 | } -start |
| 53 | |
Christopher Faulet | 58f21da | 2021-09-20 07:47:27 +0200 | [diff] [blame] | 54 | # 1 byte of the payload is missing. |
| 55 | # ==> The request must timed out with a 408 response |
Frédéric Lécaille | 02a1669 | 2018-12-21 11:56:26 +0100 | [diff] [blame] | 56 | client c1 -connect ${h1_fe1_sock} { |
| 57 | send "GET" |
| 58 | send " " |
| 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 "-this-is-a-long-url" |
| 65 | send "-this-is-a-long-url" |
| 66 | send " HTT" |
| 67 | send "P/1.1" |
| 68 | send "\r" |
| 69 | send "\n" |
| 70 | send "Content-Length: 209\r\n\r\n" |
| 71 | send "abcdefghijklmnopqrstuvwxyz" |
| 72 | send "abcdefghijklmnopqrstuvwxyz" |
| 73 | send "abcdefghijklmnopqrstuvwxyz" |
| 74 | send "abcdefghijklmnopqrstuvwxyz" |
| 75 | send "abcdefghijklmnopqrstuvwxyz" |
| 76 | send "abcdefghijklmnopqrstuvwxyz" |
| 77 | send "abcdefghijklmnopqrstuvwxyz" |
| 78 | send "abcdefghijklmnopqrstuvwxyz" |
| 79 | rxresp |
| 80 | expect resp.status == 408 |
| 81 | } -run |
| 82 | |
Christopher Faulet | 58f21da | 2021-09-20 07:47:27 +0200 | [diff] [blame] | 83 | # Payload is fully sent |
| 84 | # ==> 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] | 85 | client c2 -connect ${h1_fe1_sock} { |
| 86 | txreq -bodylen 257 |
| 87 | rxresp |
| 88 | expect resp.status == 200 |
| 89 | } -run |
| 90 | |
Christopher Faulet | 58f21da | 2021-09-20 07:47:27 +0200 | [diff] [blame] | 91 | # Payload is fully sent in 2 steps (with a small delay, smaller than the client |
| 92 | # timeout) and splitted on a chunk size. |
| 93 | # ==> Request must be sent to the server. A 200 must be received |
| 94 | client c3 -connect ${h1_fe1_sock} { |
| 95 | send "POST /1 HTTP/1.1\r\nTransfer-Encoding: chunked\r\n\r\n1\r\n1\r\n1" |
| 96 | delay 0.01 |
| 97 | send "\r\n1\r\n0\r\n\r\n" |
| 98 | rxresp |
| 99 | expect resp.status == 200 |
| 100 | } -run |
Frédéric Lécaille | 02a1669 | 2018-12-21 11:56:26 +0100 | [diff] [blame] | 101 | |
Christopher Faulet | 58f21da | 2021-09-20 07:47:27 +0200 | [diff] [blame] | 102 | # Last CRLF of the request payload is missing but payload is sent in 2 steps |
| 103 | # (with a small delay, smaller than the client timeout) and splitted on a chunk |
| 104 | # size. The client aborts before sending the last CRLF. |
| 105 | # ==> Request must be handled as an error with 'CR--' termination state. |
| 106 | client c4 -connect ${h1_fe1_sock} { |
| 107 | send "POST /2 HTTP/1.1\r\nTransfer-Encoding: chunked\r\n\r\n1\r\n1\r\n1" |
| 108 | delay 0.01 |
| 109 | send "\r\n1\r\n0\r\n" |
| 110 | } -run |
| 111 | |
| 112 | syslog S -wait |