blob: 093ba48e1377daa86bfb54bc81735c5ac127e949 [file] [log] [blame]
Christopher Faulete1b9e1b2021-03-31 17:22:31 +02001varnishtest "Test connection upgrades from TCP to HTTP"
2
3#REQUIRE_VERSION=2.4
4
5feature ignore_unknown_macro
6
7server s1 {
8 # TCP > H1 using "switch-mode http"
9 rxreq
10 expect req.http.x-stream-mode == tcp
11 expect req.http.x-name == fe1
12 txresp
13 rxreq
14 expect req.http.x-stream-mode == http
15 expect req.http.x-name == fe1
16 txresp
17
18 accept
19
20 # TCP > H1 using backend mode
21 rxreq
22 expect req.http.x-name == be
23 txresp
24 rxreq
25 expect req.http.x-name == be
26 txresp
27
28 accept
29
30 # TCP > H2 using "switch-mode http"
31 rxreq
32 expect req.http.x-stream-mode == http
33 expect req.http.x-name == fe1
34 txresp
35 rxreq
36 expect req.http.x-stream-mode == http
37 expect req.http.x-name == fe1
38 txresp
39
40 # To be sure no other request was received
41 accept
42 rxreq
43 txresp
44} -start
45
46haproxy h1 -conf {
47 frontend fe1
48 mode tcp
49 bind "fd@${fe1h1}"
50
51 tcp-request inspect-delay 1s
52 tcp-request content set-var(req.stream_mode) internal.strm.is_htx,iif(http,tcp)
53 tcp-request content switch-mode http if HTTP
54 tcp-request content reject # never reached
55
56 http-request set-header x-stream-mode %[var(req.stream_mode)]
57 http-request set-header x-name %[fe_name]
58
59 default_backend be
60
61 frontend fe2
62 mode tcp
63 bind "fd@${fe2h1}"
64 default_backend be
65
66 backend be
67 mode http
68 http-request set-header x-name %[be_name] unless { req.fhdr(x-name) -m found }
69 server s1 ${s1_addr}:${s1_port}
70
71 listen li1
72 mode http
73 bind "fd@${li1h1}"
74 server s1 ${h1_fe1h1_addr}:${h1_fe1h1_port} proto h2
75
76 listen err1
77 mode http
78 bind "fd@${err1h1}" proto h1
79 server s1 ${s1_addr}:${s1_port}
80
81 listen err2
82 mode tcp
83 bind "fd@${err2h1}"
84
85 tcp-request inspect-delay 1s
86 tcp-request content switch-mode http proto h1 if HTTP
87 tcp-request content reject # never reached
88
89 default_backend be
90
91 listen err3
92 mode tcp
93 bind "fd@${err3h1}" proto none
94
95 tcp-request inspect-delay 1s
96 tcp-request content switch-mode http if HTTP
97 tcp-request content reject # never reached
98
99 default_backend be
100} -start
101
102# TCP > H1 using "switch-mode http"
103client c1 -connect ${h1_fe1h1_sock} {
104 txreq
105 rxresp
106 expect resp.status == 200
107
108 txreq
109 rxresp
110 expect resp.status == 200
111} -run
112
113# TCP > H1 using backend mode
114client c2 -connect ${h1_fe2h1_sock} {
115 txreq
116 rxresp
117 expect resp.status == 200
118
119 txreq
120 rxresp
121 expect resp.status == 200
122} -run
123
124
125# TCP > H2 using "switch-mode http"
126client c3 -connect ${h1_li1h1_sock} {
127 txreq
128 rxresp
129 expect resp.status == 200
130
131 txreq
132 rxresp
133 expect resp.status == 200
134} -run
135
136# implicit H1 > H2 upgrade not performed
137client c_err1 -connect ${h1_err1h1_sock} {
138 send "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n"
139 rxresp
140 expect resp.status == 400
141} -run
142
143
144# TCP > H1 > H2 upgrade not allowed
145client c_err2 -connect ${h1_err2h1_sock} {
146 send "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n"
Willy Tarreaua5116352021-08-20 11:02:28 +0200147 rxresp
148 expect resp.status == 400
Christopher Faulete1b9e1b2021-03-31 17:22:31 +0200149} -run
150
151
152# TCP > HTTP upgrade not allowed
153client c_err3 -connect ${h1_err3h1_sock} {
154 txreq
155 expect_close
156} -run
157
158# To be sure no other request was received by the server
159client c_end -connect ${s1_sock} {
160 txreq
161 rxresp
162} -run