blob: 8ed683be7565b4097b6a68f754d66aea32081a5c [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
11server s1 {
12 rxreq
13 expect req.bodylen == 257
14 txresp
Christopher Faulet46e058d2021-09-20 07:47:27 +020015
16 accept
17
18 rxreq
19 expect req.bodylen == 2
20 txresp
Frédéric Lécaille02a16692018-12-21 11:56:26 +010021} -start
22
23syslog 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 Faulet46e058d2021-09-20 07:47:27 +020028 recv
29 expect ~ "[^:\\[ ]*\\[[0-9]*\\]: .* .* fe1 be1/srv1 [0-9]*/[0-9]*/[0-9]*/[0-9]*/[0-9]* 200 .* - - ---- .* .* \"POST /1 HTTP/1\\.1\""
30 recv
31 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 +010032} -start
33
34haproxy h1 -conf {
35 defaults
36 mode http
Frédéric Lécaille02a16692018-12-21 11:56:26 +010037 timeout client 100ms
38 timeout server 1s
39 timeout connect 1s
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
50} -start
51
Christopher Faulet46e058d2021-09-20 07:47:27 +020052# 1 byte of the payload is missing.
53# ==> The request must timed out with a 408 response
Frédéric Lécaille02a16692018-12-21 11:56:26 +010054client c1 -connect ${h1_fe1_sock} {
55 send "GET"
56 send " "
57 send "/this-is-a-long-url"
58 send "-this-is-a-long-url"
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 " HTT"
65 send "P/1.1"
66 send "\r"
67 send "\n"
68 send "Content-Length: 209\r\n\r\n"
69 send "abcdefghijklmnopqrstuvwxyz"
70 send "abcdefghijklmnopqrstuvwxyz"
71 send "abcdefghijklmnopqrstuvwxyz"
72 send "abcdefghijklmnopqrstuvwxyz"
73 send "abcdefghijklmnopqrstuvwxyz"
74 send "abcdefghijklmnopqrstuvwxyz"
75 send "abcdefghijklmnopqrstuvwxyz"
76 send "abcdefghijklmnopqrstuvwxyz"
77 rxresp
78 expect resp.status == 408
79} -run
80
Christopher Faulet46e058d2021-09-20 07:47:27 +020081# Payload is fully sent
82# ==> Request must be sent to the server. A 200 must be received
Frédéric Lécaille02a16692018-12-21 11:56:26 +010083client c2 -connect ${h1_fe1_sock} {
84 txreq -bodylen 257
85 rxresp
86 expect resp.status == 200
87} -run
88
Christopher Faulet46e058d2021-09-20 07:47:27 +020089# Payload is fully sent in 2 steps (with a small delay, smaller than the client
90# timeout) and splitted on a chunk size.
91# ==> Request must be sent to the server. A 200 must be received
92client c3 -connect ${h1_fe1_sock} {
93 send "POST /1 HTTP/1.1\r\nTransfer-Encoding: chunked\r\n\r\n1\r\n1\r\n1"
94 delay 0.01
95 send "\r\n1\r\n0\r\n\r\n"
96 rxresp
97 expect resp.status == 200
98} -run
Frédéric Lécaille02a16692018-12-21 11:56:26 +010099
Christopher Faulet46e058d2021-09-20 07:47:27 +0200100# Last CRLF of the request payload is missing but payload is sent in 2 steps
101# (with a small delay, smaller than the client timeout) and splitted on a chunk
102# size. The client aborts before sending the last CRLF.
103# ==> Request must be handled as an error with 'CR--' termination state.
104client c4 -connect ${h1_fe1_sock} {
105 send "POST /2 HTTP/1.1\r\nTransfer-Encoding: chunked\r\n\r\n1\r\n1\r\n1"
106 delay 0.01
107 send "\r\n1\r\n0\r\n"
108} -run
109
110syslog S -wait