blob: f1cec1a2cba2155afbe88a3e67c5ca497277379e [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
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
12server s1 {
13 rxreq
14 expect req.bodylen == 257
15 txresp
Christopher Faulet58f21da2021-09-20 07:47:27 +020016
17 accept
18
19 rxreq
20 expect req.bodylen == 2
21 txresp
Frédéric Lécaille02a16692018-12-21 11:56:26 +010022} -start
23
24syslog 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 Faulet58f21da2021-09-20 07:47:27 +020029 recv
Christopher Fauletdd259aa2022-06-02 14:01:30 +020030 expect ~ "[^:\\[ ]*\\[[0-9]*\\]: .* .* fe2 be1/srv1 [0-9]*/[0-9]*/[0-9]*/[0-9]*/[0-9]* 200 .* - - ---- .* .* \"POST /1 HTTP/1\\.1\""
Christopher Faulet58f21da2021-09-20 07:47:27 +020031 recv
Christopher Fauletdd259aa2022-06-02 14:01:30 +020032 expect ~ "[^:\\[ ]*\\[[0-9]*\\]: .* .* fe2 be1/<NOSRV> [0-9]*/-1/-1/-1/[0-9]* -1 .* - - CR-- .* .* \"POST /2 HTTP/1\\.1\""
Frédéric Lécaille02a16692018-12-21 11:56:26 +010033} -start
34
35haproxy 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
Christopher Fauletdd259aa2022-06-02 14:01:30 +020052
53 frontend fe2
54 timeout client 10s
55 option httplog
56 option http-buffer-request
57 log ${S_addr}:${S_port} local0 debug err
58 bind "fd@${fe2}"
59 use_backend be1
Frédéric Lécaille02a16692018-12-21 11:56:26 +010060} -start
61
Christopher Faulet58f21da2021-09-20 07:47:27 +020062# 1 byte of the payload is missing.
63# ==> The request must timed out with a 408 response
Frédéric Lécaille02a16692018-12-21 11:56:26 +010064client c1 -connect ${h1_fe1_sock} {
65 send "GET"
66 send " "
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 "-this-is-a-long-url"
73 send "-this-is-a-long-url"
74 send " HTT"
75 send "P/1.1"
76 send "\r"
77 send "\n"
78 send "Content-Length: 209\r\n\r\n"
79 send "abcdefghijklmnopqrstuvwxyz"
80 send "abcdefghijklmnopqrstuvwxyz"
81 send "abcdefghijklmnopqrstuvwxyz"
82 send "abcdefghijklmnopqrstuvwxyz"
83 send "abcdefghijklmnopqrstuvwxyz"
84 send "abcdefghijklmnopqrstuvwxyz"
85 send "abcdefghijklmnopqrstuvwxyz"
86 send "abcdefghijklmnopqrstuvwxyz"
87 rxresp
88 expect resp.status == 408
89} -run
90
Christopher Faulet58f21da2021-09-20 07:47:27 +020091# Payload is fully sent
92# ==> Request must be sent to the server. A 200 must be received
Frédéric Lécaille02a16692018-12-21 11:56:26 +010093client c2 -connect ${h1_fe1_sock} {
94 txreq -bodylen 257
95 rxresp
96 expect resp.status == 200
97} -run
98
Christopher Faulet58f21da2021-09-20 07:47:27 +020099# Payload is fully sent in 2 steps (with a small delay, smaller than the client
100# timeout) and splitted on a chunk size.
101# ==> Request must be sent to the server. A 200 must be received
Christopher Fauletdd259aa2022-06-02 14:01:30 +0200102client c3 -connect ${h1_fe2_sock} {
Christopher Faulet58f21da2021-09-20 07:47:27 +0200103 send "POST /1 HTTP/1.1\r\nTransfer-Encoding: chunked\r\n\r\n1\r\n1\r\n1"
104 delay 0.01
105 send "\r\n1\r\n0\r\n\r\n"
106 rxresp
107 expect resp.status == 200
108} -run
Frédéric Lécaille02a16692018-12-21 11:56:26 +0100109
Christopher Faulet58f21da2021-09-20 07:47:27 +0200110# Last CRLF of the request payload is missing but payload is sent in 2 steps
111# (with a small delay, smaller than the client timeout) and splitted on a chunk
112# size. The client aborts before sending the last CRLF.
113# ==> Request must be handled as an error with 'CR--' termination state.
Christopher Fauletdd259aa2022-06-02 14:01:30 +0200114client c4 -connect ${h1_fe2_sock} {
Christopher Faulet58f21da2021-09-20 07:47:27 +0200115 send "POST /2 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"
118} -run
119
120syslog S -wait