blob: 753aafe2784ec9d0028934cc3cbca1953be5e604 [file] [log] [blame]
Amaury Denoyellebda34302020-12-11 17:53:11 +01001# This reg-test checks the full support of HTTP protocol upgrade, using a GET
2# method and a Connection: Upgrade header. The equivalent mechanism has been
3# defined in rfc8441 for HTTP/2 using CONNECT and a new pseudo-header
4# :protocol. Check that haproxy handles properly h1/h2 translation of protocol
5# upgrade requests and responses.
6
7varnishtest "h1/h2 support for protocol upgrade test"
8
9feature ignore_unknown_macro
10
Christopher Faulet85a81362020-12-15 17:13:39 +010011#REQUIRE_VERSION=2.4
12
Amaury Denoyellebda34302020-12-11 17:53:11 +010013# http/1.1 server
14server srv_h1 {
15 rxreq
16 expect req.method == "GET"
17 expect req.http.connection == "upgrade"
18 expect req.http.upgrade == "custom_protocol"
19
20 txresp \
21 -status 101 \
22 -hdr "connection: upgrade" \
23 -hdr "upgrade: custom_protocol"
24} -repeat 2 -start
25
26# http2 server
27server srv_h2 {
28 rxpri
29
30 stream 0 {
31 txsettings
32 rxsettings
33 txsettings -ack
34 rxsettings
35 expect settings.ack == true
36 } -run
37
38 stream 1 {
39 rxhdrs
40 expect req.method == "CONNECT"
41 expect req.http.:scheme == "https"
42 expect req.http.:path == "/"
43 expect req.http.:authority == "127.0.0.1"
44 expect req.http.:protocol == "custom_protocol"
45
46 txresp \
47 -status 200
48 } -run
49} -repeat 2 -start
50
51haproxy hap -conf {
52 defaults
53 mode http
54 ${no-htx} option http-use-htx
55 timeout connect 1s
56 timeout client 1s
57 timeout server 1s
58
59 # h1 frontend connected to h2 frontend
60 listen frt_h1_h2
61 bind "fd@${frt_h1_h2}"
62 server feh2_srv ${hap_frt_h2_addr}:${hap_frt_h2_port} proto h2
63
64 # h2 frontend connected to srv_h1
65 listen frt_h2
66 bind "fd@${frt_h2}" proto h2
67 server srv_h1 ${srv_h1_addr}:${srv_h1_port}
68
69 # h1 frontend connected to srv_h2
70 listen frt_h1
71 bind "fd@${frt_h1}"
72 server srv_h2 ${srv_h2_addr}:${srv_h2_port} proto h2
73
74 # h2 frontend connected to h1 frontend
75 listen frt_h2_h1
76 bind "fd@${frt_h2_h1}" proto h2
77 server frt_h1 ${hap_frt_h1_addr}:${hap_frt_h1_port}
78} -start
79
80## connect to h1 translation frontend
81client c1_h1_h2 -connect ${hap_frt_h1_h2_sock} {
82 txreq \
83 -req "GET" \
84 -url "/" \
85 -hdr "host: 127.0.0.1" \
86 -hdr "connection: upgrade" \
87 -hdr "upgrade: custom_protocol"
88
89 rxresp
90 expect resp.status == 101
91 expect resp.http.connection == "upgrade"
92 expect resp.http.upgrade == "custom_protocol"
93} -run
94
95# connect to h2 server frontend
96client c2_h2 -connect ${hap_frt_h2_sock} {
97 txpri
98 stream 0 {
99 txsettings
100 rxsettings
101 txsettings -ack
102 rxsettings
103 expect settings.ack == true
104 } -run
105
106 stream 1 {
107 txreq \
108 -req "CONNECT" \
109 -scheme "http" \
110 -url "/" \
111 -hdr ":authority" "127.0.0.1" \
112 -hdr ":protocol" "custom_protocol"
113
114 rxhdrs
115 expect resp.status == 200
116 } -run
117} -run
118
119# connect to h2 translation frontend
120client c3_h2_h1 -connect ${hap_frt_h2_h1_sock} {
121 txpri
122 stream 0 {
123 txsettings
124 rxsettings
125 txsettings -ack
126 rxsettings
127 expect settings.ack == true
128 } -run
129
130 stream 1 {
131 txreq \
132 -req "CONNECT" \
133 -scheme "http" \
134 -url "/" \
135 -hdr ":authority" "127.0.0.1" \
136 -hdr ":protocol" "custom_protocol"
137
138 rxhdrs
139 expect resp.status == 200
140 } -run
141} -run
142
143# connect to h1 server frontend
144client c4_h1 -connect ${hap_frt_h1_sock} {
145 txreq \
146 -req "GET" \
147 -url "/" \
148 -hdr "host: 127.0.0.1" \
149 -hdr "connection: upgrade" \
150 -hdr "upgrade: custom_protocol"
151
152 rxresp
153 expect resp.status == 101
154 expect resp.http.connection == "upgrade"
155 expect resp.http.upgrade == "custom_protocol"
156} -run