blob: e712e32e4a05b2e3ce5da120cadd71b03cb76b37 [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
Christopher Faulet6cacd012022-09-01 19:46:28 +020012barrier b1 cond 2 -cyclic
13
Frédéric Lécaille02a16692018-12-21 11:56:26 +010014server s1 {
15 rxreq
16 expect req.bodylen == 257
17 txresp
Christopher Faulet58f21da2021-09-20 07:47:27 +020018
19 accept
20
21 rxreq
22 expect req.bodylen == 2
23 txresp
Frédéric Lécaille02a16692018-12-21 11:56:26 +010024} -start
25
26syslog S -level info {
27 recv
Christopher Faulet1a023fa2023-01-13 10:49:31 +010028 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 Faulet6cacd012022-09-01 19:46:28 +020029 barrier b1 sync
30
Frédéric Lécaille02a16692018-12-21 11:56:26 +010031 recv
32 expect ~ "[^:\\[ ]*\\[[0-9]*\\]: .* .* fe1 be1/srv1 [0-9]*/[0-9]*/[0-9]*/[0-9]*/[0-9]* 200 .* - - ---- .* .* \"GET / HTTP/1\\.1\""
Christopher Faulet6cacd012022-09-01 19:46:28 +020033 barrier b1 sync
34
Christopher Faulet58f21da2021-09-20 07:47:27 +020035 recv
Christopher Fauletdd259aa2022-06-02 14:01:30 +020036 expect ~ "[^:\\[ ]*\\[[0-9]*\\]: .* .* fe2 be1/srv1 [0-9]*/[0-9]*/[0-9]*/[0-9]*/[0-9]* 200 .* - - ---- .* .* \"POST /1 HTTP/1\\.1\""
Christopher Faulet6cacd012022-09-01 19:46:28 +020037 barrier b1 sync
38
Christopher Faulet58f21da2021-09-20 07:47:27 +020039 recv
Christopher Fauletdd259aa2022-06-02 14:01:30 +020040 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 +010041} -start
42
43haproxy 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 Fauletdd259aa2022-06-02 14:01:30 +020060
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écaille02a16692018-12-21 11:56:26 +010068} -start
69
Christopher Faulet58f21da2021-09-20 07:47:27 +020070# 1 byte of the payload is missing.
71# ==> The request must timed out with a 408 response
Frédéric Lécaille02a16692018-12-21 11:56:26 +010072client 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 Faulet6cacd012022-09-01 19:46:28 +020099# Wait matching on log message
100barrier b1 sync
101
Christopher Faulet58f21da2021-09-20 07:47:27 +0200102# Payload is fully sent
103# ==> Request must be sent to the server. A 200 must be received
Frédéric Lécaille02a16692018-12-21 11:56:26 +0100104client c2 -connect ${h1_fe1_sock} {
105 txreq -bodylen 257
106 rxresp
107 expect resp.status == 200
108} -run
109
Christopher Faulet6cacd012022-09-01 19:46:28 +0200110# Wait matching on log message
111barrier b1 sync
112
Christopher Faulet58f21da2021-09-20 07:47:27 +0200113# 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 Fauletdd259aa2022-06-02 14:01:30 +0200116client c3 -connect ${h1_fe2_sock} {
Christopher Faulet58f21da2021-09-20 07:47:27 +0200117 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écaille02a16692018-12-21 11:56:26 +0100123
Christopher Faulet6cacd012022-09-01 19:46:28 +0200124# Wait matching on log message
125barrier b1 sync
126
Christopher Faulet58f21da2021-09-20 07:47:27 +0200127# 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 Fauletdd259aa2022-06-02 14:01:30 +0200131client c4 -connect ${h1_fe2_sock} {
Christopher Faulet58f21da2021-09-20 07:47:27 +0200132 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
137syslog S -wait