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