blob: 4fd7bb2885cdcb63c76a049a253a49000fc78fad [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
30 expect ~ "[^:\\[ ]*\\[[0-9]*\\]: .* .* fe1 be1/srv1 [0-9]*/[0-9]*/[0-9]*/[0-9]*/[0-9]* 200 .* - - ---- .* .* \"POST /1 HTTP/1\\.1\""
31 recv
32 expect ~ "[^:\\[ ]*\\[[0-9]*\\]: .* .* fe1 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
52} -start
53
Christopher Faulet58f21da2021-09-20 07:47:27 +020054# 1 byte of the payload is missing.
55# ==> The request must timed out with a 408 response
Frédéric Lécaille02a16692018-12-21 11:56:26 +010056client c1 -connect ${h1_fe1_sock} {
57 send "GET"
58 send " "
59 send "/this-is-a-long-url"
60 send "-this-is-a-long-url"
61 send "-this-is-a-long-url"
62 send "-this-is-a-long-url"
63 send "-this-is-a-long-url"
64 send "-this-is-a-long-url"
65 send "-this-is-a-long-url"
66 send " HTT"
67 send "P/1.1"
68 send "\r"
69 send "\n"
70 send "Content-Length: 209\r\n\r\n"
71 send "abcdefghijklmnopqrstuvwxyz"
72 send "abcdefghijklmnopqrstuvwxyz"
73 send "abcdefghijklmnopqrstuvwxyz"
74 send "abcdefghijklmnopqrstuvwxyz"
75 send "abcdefghijklmnopqrstuvwxyz"
76 send "abcdefghijklmnopqrstuvwxyz"
77 send "abcdefghijklmnopqrstuvwxyz"
78 send "abcdefghijklmnopqrstuvwxyz"
79 rxresp
80 expect resp.status == 408
81} -run
82
Christopher Faulet58f21da2021-09-20 07:47:27 +020083# Payload is fully sent
84# ==> Request must be sent to the server. A 200 must be received
Frédéric Lécaille02a16692018-12-21 11:56:26 +010085client c2 -connect ${h1_fe1_sock} {
86 txreq -bodylen 257
87 rxresp
88 expect resp.status == 200
89} -run
90
Christopher Faulet58f21da2021-09-20 07:47:27 +020091# Payload is fully sent in 2 steps (with a small delay, smaller than the client
92# timeout) and splitted on a chunk size.
93# ==> Request must be sent to the server. A 200 must be received
94client c3 -connect ${h1_fe1_sock} {
95 send "POST /1 HTTP/1.1\r\nTransfer-Encoding: chunked\r\n\r\n1\r\n1\r\n1"
96 delay 0.01
97 send "\r\n1\r\n0\r\n\r\n"
98 rxresp
99 expect resp.status == 200
100} -run
Frédéric Lécaille02a16692018-12-21 11:56:26 +0100101
Christopher Faulet58f21da2021-09-20 07:47:27 +0200102# Last CRLF of the request payload is missing but payload is sent in 2 steps
103# (with a small delay, smaller than the client timeout) and splitted on a chunk
104# size. The client aborts before sending the last CRLF.
105# ==> Request must be handled as an error with 'CR--' termination state.
106client c4 -connect ${h1_fe1_sock} {
107 send "POST /2 HTTP/1.1\r\nTransfer-Encoding: chunked\r\n\r\n1\r\n1\r\n1"
108 delay 0.01
109 send "\r\n1\r\n0\r\n"
110} -run
111
112syslog S -wait