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