blob: a45d1550337b8884801e8816c626a4cda56ace35 [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
Christopher Faulet33a27452022-06-02 14:01:30 +020029 expect ~ "[^:\\[ ]*\\[[0-9]*\\]: .* .* fe2 be1/srv1 [0-9]*/[0-9]*/[0-9]*/[0-9]*/[0-9]* 200 .* - - ---- .* .* \"POST /1 HTTP/1\\.1\""
Christopher Faulet46e058d2021-09-20 07:47:27 +020030 recv
Christopher Faulet33a27452022-06-02 14:01:30 +020031 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 +010032} -start
33
34haproxy h1 -conf {
35 defaults
36 mode http
Willy Tarreauf6739232021-11-18 17:46:22 +010037 timeout client 100
38 timeout server "${HAPROXY_TEST_TIMEOUT-5s}"
39 timeout connect "${HAPROXY_TEST_TIMEOUT-5s}"
Frédéric Lécaille02a16692018-12-21 11:56:26 +010040
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
Christopher Faulet33a27452022-06-02 14:01:30 +020050
51 frontend fe2
52 timeout client 10s
53 option httplog
54 option http-buffer-request
55 log ${S_addr}:${S_port} local0 debug err
56 bind "fd@${fe2}"
57 use_backend be1
Frédéric Lécaille02a16692018-12-21 11:56:26 +010058} -start
59
Christopher Faulet46e058d2021-09-20 07:47:27 +020060# 1 byte of the payload is missing.
61# ==> The request must timed out with a 408 response
Frédéric Lécaille02a16692018-12-21 11:56:26 +010062client c1 -connect ${h1_fe1_sock} {
63 send "GET"
64 send " "
65 send "/this-is-a-long-url"
66 send "-this-is-a-long-url"
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 " HTT"
73 send "P/1.1"
74 send "\r"
75 send "\n"
76 send "Content-Length: 209\r\n\r\n"
77 send "abcdefghijklmnopqrstuvwxyz"
78 send "abcdefghijklmnopqrstuvwxyz"
79 send "abcdefghijklmnopqrstuvwxyz"
80 send "abcdefghijklmnopqrstuvwxyz"
81 send "abcdefghijklmnopqrstuvwxyz"
82 send "abcdefghijklmnopqrstuvwxyz"
83 send "abcdefghijklmnopqrstuvwxyz"
84 send "abcdefghijklmnopqrstuvwxyz"
85 rxresp
86 expect resp.status == 408
87} -run
88
Christopher Faulet46e058d2021-09-20 07:47:27 +020089# Payload is fully sent
90# ==> Request must be sent to the server. A 200 must be received
Frédéric Lécaille02a16692018-12-21 11:56:26 +010091client c2 -connect ${h1_fe1_sock} {
92 txreq -bodylen 257
93 rxresp
94 expect resp.status == 200
95} -run
96
Christopher Faulet46e058d2021-09-20 07:47:27 +020097# Payload is fully sent in 2 steps (with a small delay, smaller than the client
Ilya Shipitsinbd6b4be2021-10-15 16:18:21 +050098# timeout) and split on a chunk size.
Christopher Faulet46e058d2021-09-20 07:47:27 +020099# ==> Request must be sent to the server. A 200 must be received
Christopher Faulet33a27452022-06-02 14:01:30 +0200100client c3 -connect ${h1_fe2_sock} {
Christopher Faulet46e058d2021-09-20 07:47:27 +0200101 send "POST /1 HTTP/1.1\r\nTransfer-Encoding: chunked\r\n\r\n1\r\n1\r\n1"
102 delay 0.01
103 send "\r\n1\r\n0\r\n\r\n"
104 rxresp
105 expect resp.status == 200
106} -run
Frédéric Lécaille02a16692018-12-21 11:56:26 +0100107
Christopher Faulet46e058d2021-09-20 07:47:27 +0200108# Last CRLF of the request payload is missing but payload is sent in 2 steps
Ilya Shipitsinbd6b4be2021-10-15 16:18:21 +0500109# (with a small delay, smaller than the client timeout) and split on a chunk
Christopher Faulet46e058d2021-09-20 07:47:27 +0200110# size. The client aborts before sending the last CRLF.
111# ==> Request must be handled as an error with 'CR--' termination state.
Christopher Faulet33a27452022-06-02 14:01:30 +0200112client c4 -connect ${h1_fe2_sock} {
Christopher Faulet46e058d2021-09-20 07:47:27 +0200113 send "POST /2 HTTP/1.1\r\nTransfer-Encoding: chunked\r\n\r\n1\r\n1\r\n1"
114 delay 0.01
115 send "\r\n1\r\n0\r\n"
116} -run
117
118syslog S -wait