blob: 302db4ab4e01091104bd5f2c6db5d1463ed7fc97 [file] [log] [blame]
Frédéric Lécaille02a16692018-12-21 11:56:26 +01001varnishtest "A test for http-request-buffer option"
2feature ignore_unknown_macro
3
Frédéric Lécaille02a16692018-12-21 11:56:26 +01004
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 Faulet05ed05b2022-09-01 19:46:28 +020011barrier b1 cond 2 -cyclic
12
Frédéric Lécaille02a16692018-12-21 11:56:26 +010013server s1 {
14 rxreq
15 expect req.bodylen == 257
16 txresp
Christopher Faulet46e058d2021-09-20 07:47:27 +020017
18 accept
19
20 rxreq
21 expect req.bodylen == 2
22 txresp
Frédéric Lécaille02a16692018-12-21 11:56:26 +010023} -start
24
25syslog S -level info {
26 recv
Christopher Fauletf4569bb2023-01-13 10:49:31 +010027 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 Faulet05ed05b2022-09-01 19:46:28 +020028 barrier b1 sync
29
Frédéric Lécaille02a16692018-12-21 11:56:26 +010030 recv
31 expect ~ "[^:\\[ ]*\\[[0-9]*\\]: .* .* fe1 be1/srv1 [0-9]*/[0-9]*/[0-9]*/[0-9]*/[0-9]* 200 .* - - ---- .* .* \"GET / HTTP/1\\.1\""
Christopher Faulet05ed05b2022-09-01 19:46:28 +020032 barrier b1 sync
33
Christopher Faulet46e058d2021-09-20 07:47:27 +020034 recv
Christopher Faulet33a27452022-06-02 14:01:30 +020035 expect ~ "[^:\\[ ]*\\[[0-9]*\\]: .* .* fe2 be1/srv1 [0-9]*/[0-9]*/[0-9]*/[0-9]*/[0-9]* 200 .* - - ---- .* .* \"POST /1 HTTP/1\\.1\""
Christopher Faulet05ed05b2022-09-01 19:46:28 +020036 barrier b1 sync
37
Christopher Faulet46e058d2021-09-20 07:47:27 +020038 recv
Christopher Fauletf2b02cf2023-01-13 11:02:28 +010039 expect ~ "[^:\\[ ]*\\[[0-9]*\\]: .* .* fe2 be1/<NOSRV> [0-9]*/-1/-1/-1/[0-9]* 400 .* - - CR-- .* .* \"POST /2 HTTP/1\\.1\""
Frédéric Lécaille02a16692018-12-21 11:56:26 +010040} -start
41
42haproxy h1 -conf {
43 defaults
44 mode http
Willy Tarreauf6739232021-11-18 17:46:22 +010045 timeout client 100
46 timeout server "${HAPROXY_TEST_TIMEOUT-5s}"
47 timeout connect "${HAPROXY_TEST_TIMEOUT-5s}"
Frédéric Lécaille02a16692018-12-21 11:56:26 +010048
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 Faulet33a27452022-06-02 14:01:30 +020058
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écaille02a16692018-12-21 11:56:26 +010066} -start
67
Christopher Faulet46e058d2021-09-20 07:47:27 +020068# 1 byte of the payload is missing.
69# ==> The request must timed out with a 408 response
Frédéric Lécaille02a16692018-12-21 11:56:26 +010070client 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 Faulet05ed05b2022-09-01 19:46:28 +020097# Wait matching on log message
98barrier b1 sync
99
Christopher Faulet46e058d2021-09-20 07:47:27 +0200100# Payload is fully sent
101# ==> Request must be sent to the server. A 200 must be received
Frédéric Lécaille02a16692018-12-21 11:56:26 +0100102client c2 -connect ${h1_fe1_sock} {
103 txreq -bodylen 257
104 rxresp
105 expect resp.status == 200
106} -run
107
Christopher Faulet05ed05b2022-09-01 19:46:28 +0200108# Wait matching on log message
109barrier b1 sync
110
Christopher Faulet46e058d2021-09-20 07:47:27 +0200111# Payload is fully sent in 2 steps (with a small delay, smaller than the client
Ilya Shipitsinbd6b4be2021-10-15 16:18:21 +0500112# timeout) and split on a chunk size.
Christopher Faulet46e058d2021-09-20 07:47:27 +0200113# ==> Request must be sent to the server. A 200 must be received
Christopher Faulet33a27452022-06-02 14:01:30 +0200114client c3 -connect ${h1_fe2_sock} {
Christopher Faulet46e058d2021-09-20 07:47:27 +0200115 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écaille02a16692018-12-21 11:56:26 +0100121
Christopher Faulet05ed05b2022-09-01 19:46:28 +0200122# Wait matching on log message
123barrier b1 sync
124
Christopher Faulet46e058d2021-09-20 07:47:27 +0200125# Last CRLF of the request payload is missing but payload is sent in 2 steps
Ilya Shipitsinbd6b4be2021-10-15 16:18:21 +0500126# (with a small delay, smaller than the client timeout) and split on a chunk
Christopher Faulet46e058d2021-09-20 07:47:27 +0200127# size. The client aborts before sending the last CRLF.
128# ==> Request must be handled as an error with 'CR--' termination state.
Christopher Faulet33a27452022-06-02 14:01:30 +0200129client c4 -connect ${h1_fe2_sock} {
Christopher Faulet46e058d2021-09-20 07:47:27 +0200130 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
135syslog S -wait