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 |
Christopher Faulet | 33a2745 | 2022-06-02 14:01:30 +0200 | [diff] [blame^] | 29 | expect ~ "[^:\\[ ]*\\[[0-9]*\\]: .* .* fe2 be1/srv1 [0-9]*/[0-9]*/[0-9]*/[0-9]*/[0-9]* 200 .* - - ---- .* .* \"POST /1 HTTP/1\\.1\"" |
Christopher Faulet | 46e058d | 2021-09-20 07:47:27 +0200 | [diff] [blame] | 30 | recv |
Christopher Faulet | 33a2745 | 2022-06-02 14:01:30 +0200 | [diff] [blame^] | 31 | 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] | 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 |
Christopher Faulet | 33a2745 | 2022-06-02 14:01:30 +0200 | [diff] [blame^] | 50 | |
| 51 | frontend fe2 |
| 52 | timeout client 10s |
| 53 | option httplog |
| 54 | option http-buffer-request |
| 55 | log ${S_addr}:${S_port} local0 debug err |
| 56 | bind "fd@${fe2}" |
| 57 | use_backend be1 |
Frédéric Lécaille | 02a1669 | 2018-12-21 11:56:26 +0100 | [diff] [blame] | 58 | } -start |
| 59 | |
Christopher Faulet | 46e058d | 2021-09-20 07:47:27 +0200 | [diff] [blame] | 60 | # 1 byte of the payload is missing. |
| 61 | # ==> The request must timed out with a 408 response |
Frédéric Lécaille | 02a1669 | 2018-12-21 11:56:26 +0100 | [diff] [blame] | 62 | client c1 -connect ${h1_fe1_sock} { |
| 63 | send "GET" |
| 64 | send " " |
| 65 | send "/this-is-a-long-url" |
| 66 | send "-this-is-a-long-url" |
| 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 " HTT" |
| 73 | send "P/1.1" |
| 74 | send "\r" |
| 75 | send "\n" |
| 76 | send "Content-Length: 209\r\n\r\n" |
| 77 | send "abcdefghijklmnopqrstuvwxyz" |
| 78 | send "abcdefghijklmnopqrstuvwxyz" |
| 79 | send "abcdefghijklmnopqrstuvwxyz" |
| 80 | send "abcdefghijklmnopqrstuvwxyz" |
| 81 | send "abcdefghijklmnopqrstuvwxyz" |
| 82 | send "abcdefghijklmnopqrstuvwxyz" |
| 83 | send "abcdefghijklmnopqrstuvwxyz" |
| 84 | send "abcdefghijklmnopqrstuvwxyz" |
| 85 | rxresp |
| 86 | expect resp.status == 408 |
| 87 | } -run |
| 88 | |
Christopher Faulet | 46e058d | 2021-09-20 07:47:27 +0200 | [diff] [blame] | 89 | # Payload is fully sent |
| 90 | # ==> 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] | 91 | client c2 -connect ${h1_fe1_sock} { |
| 92 | txreq -bodylen 257 |
| 93 | rxresp |
| 94 | expect resp.status == 200 |
| 95 | } -run |
| 96 | |
Christopher Faulet | 46e058d | 2021-09-20 07:47:27 +0200 | [diff] [blame] | 97 | # 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] | 98 | # timeout) and split on a chunk size. |
Christopher Faulet | 46e058d | 2021-09-20 07:47:27 +0200 | [diff] [blame] | 99 | # ==> Request must be sent to the server. A 200 must be received |
Christopher Faulet | 33a2745 | 2022-06-02 14:01:30 +0200 | [diff] [blame^] | 100 | client c3 -connect ${h1_fe2_sock} { |
Christopher Faulet | 46e058d | 2021-09-20 07:47:27 +0200 | [diff] [blame] | 101 | send "POST /1 HTTP/1.1\r\nTransfer-Encoding: chunked\r\n\r\n1\r\n1\r\n1" |
| 102 | delay 0.01 |
| 103 | send "\r\n1\r\n0\r\n\r\n" |
| 104 | rxresp |
| 105 | expect resp.status == 200 |
| 106 | } -run |
Frédéric Lécaille | 02a1669 | 2018-12-21 11:56:26 +0100 | [diff] [blame] | 107 | |
Christopher Faulet | 46e058d | 2021-09-20 07:47:27 +0200 | [diff] [blame] | 108 | # 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] | 109 | # (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] | 110 | # size. The client aborts before sending the last CRLF. |
| 111 | # ==> Request must be handled as an error with 'CR--' termination state. |
Christopher Faulet | 33a2745 | 2022-06-02 14:01:30 +0200 | [diff] [blame^] | 112 | client c4 -connect ${h1_fe2_sock} { |
Christopher Faulet | 46e058d | 2021-09-20 07:47:27 +0200 | [diff] [blame] | 113 | send "POST /2 HTTP/1.1\r\nTransfer-Encoding: chunked\r\n\r\n1\r\n1\r\n1" |
| 114 | delay 0.01 |
| 115 | send "\r\n1\r\n0\r\n" |
| 116 | } -run |
| 117 | |
| 118 | syslog S -wait |