blob: 99e454933db318a42bbbe5aa56106769c73b45a8 [file] [log] [blame]
Willy Tarreau116f91e2010-01-17 11:43:59 +010012010/01/16 - Connection header adjustments depending on the transaction mode.
2
3
4HTTP transactions supports 5 possible modes :
5
6 WANT_TUN : default, nothing changed
7 WANT_TUN + httpclose : headers set for close in both dirs
8 WANT_KAL : keep-alive desired in both dirs
9 WANT_SCL : want close with the server and KA with the client
10 WANT_CLO : want close on both sides.
11
12When only WANT_TUN is set, nothing is changed nor analysed, so for commodity
13below, we'll refer to WANT_TUN+httpclose as WANT_TUN.
14
15The mode is adjusted in 3 steps :
16 - configuration sets initial mode
17 - request headers set required request mode
18 - response headers set the final mode
19
20
211) Adjusting the initial mode via the configuration
22
23 option httpclose => TUN
24 option http-keep-alive => KAL
25 option http-server-close => SCL
26 option forceclose => CLO
27
28Note that option httpclose combined with any other option is equivalent to
29forceclose.
30
31
322) Adjusting the request mode once the request is parsed
33
34If we cannot determine the body length from the headers, we set the mode to CLO
35but later we'll switch to tunnel mode once forwarding the body. That way, all
36parties are informed of the correct mode.
37
38Depending on the request version and request Connection header, we may have to
39adjust the current transaction mode and to update the connection header.
40
41mode req_ver req_hdr new_mode hdr_change
42TUN 1.0 - TUN -
43TUN 1.0 ka TUN del_ka
44TUN 1.0 close TUN del_close
45TUN 1.0 both TUN del_ka, del_close
46
47TUN 1.1 - TUN add_close
48TUN 1.1 ka TUN del_ka, add_close
49TUN 1.1 close TUN -
50TUN 1.1 both TUN del_ka
51
52KAL 1.0 - CLO -
53KAL 1.0 ka KAL -
54KAL 1.0 close CLO del_close
55KAL 1.0 both CLO del_ka, del_close
56
57KAL 1.1 - KAL -
58KAL 1.1 ka KAL del_ka
59KAL 1.1 close CLO -
60KAL 1.1 both CLO del_ka
61
62SCL 1.0 - CLO -
63SCL 1.0 ka SCL del_ka
64SCL 1.0 close CLO del_close
65SCL 1.0 both CLO del_ka, del_close
66
67SCL 1.1 - SCL add_close
68SCL 1.1 ka SCL del_ka, add_close
69SCL 1.1 close CLO -
70SCL 1.1 both CLO del_ka
71
72CLO 1.0 - CLO -
73CLO 1.0 ka CLO del_ka
Willy Tarreau60466522010-01-18 19:08:45 +010074CLO 1.0 close CLO del_close
Willy Tarreau116f91e2010-01-17 11:43:59 +010075CLO 1.0 both CLO del_ka, del_close
76
77CLO 1.1 - CLO add_close
78CLO 1.1 ka CLO del_ka, add_close
79CLO 1.1 close CLO -
80CLO 1.1 both CLO del_ka
81
82=> Summary:
83 - KAL and SCL are only possible with the same requests :
84 - 1.0 + ka
85 - 1.1 + ka or nothing
86
87 - CLO is assumed for any non-TUN request which contains at least a close
88 header, as well as for any 1.0 request without a keep-alive header.
89
90 - del_ka is set whenever we want a CLO or SCL or TUN and req contains a KA,
91 or when the req is 1.1 and contains a KA.
92
93 - del_close is set whenever a 1.0 request contains a close.
94
95 - add_close is set whenever a 1.1 request must be switched to TUN, SCL, CLO
96 and did not have a close hdr.
97
98Note that the request processing is performed in two passes, one with the
99frontend's config and a second one with the backend's config. It is only
100possible to "raise" the mode between them, so during the second pass, we have
101no reason to re-add a header that we previously removed. As an exception, the
102TUN mode is converted to CLO once combined because in fact it's an httpclose
103option set on a TUN mode connection :
104
105 BE (2)
106 | TUN KAL SCL CLO
107 ----+----+----+----+----
108 TUN | TUN CLO CLO CLO
109 +
110 KAL | CLO KAL SCL CLO
111 FE +
112 (1) SCL | CLO SCL SCL CLO
113 +
114 CLO | CLO CLO CLO CLO
115
116
1173) Adjusting the final mode once the response is parsed
118
119This part becomes trickier. It is possible that the server responds with a
120version that the client does not necessarily understand. Obviously, 1.1 clients
121are asusmed to understand 1.0 responses. The problematic case is a 1.0 client
122receiving a 1.1 response without any Connection header. Some 1.0 clients might
123know that in 1.1 this means "keep-alive" while others might ignore the version
124and assume a "close". Since we know the version on both sides, we may have to
125adjust some responses to remove any ambiguous case. That's the reason why the
126following table considers both the request and the response version. If the
127response length cannot be determined, we switch to CLO mode.
128
129mode res_ver res_hdr req_ver new_mode hdr_change
130TUN 1.0 - any TUN -
131TUN 1.0 ka any TUN del_ka
132TUN 1.0 close any TUN del_close
133TUN 1.0 both any TUN del_ka, del_close
134
135TUN 1.1 - any TUN add_close
136TUN 1.1 ka any TUN del_ka, add_close
137TUN 1.1 close any TUN -
138TUN 1.1 both any TUN del_ka
139
140KAL 1.0 - any SCL add_ka
141KAL 1.0 ka any KAL -
142KAL 1.0 close any SCL del_close, add_ka
143KAL 1.0 both any SCL del_close
144
145KAL 1.1 - 1.0 KAL add_ka
146KAL 1.1 - 1.1 KAL -
147KAL 1.1 ka 1.0 KAL -
148KAL 1.1 ka 1.1 KAL del_ka
149KAL 1.1 close 1.0 SCL del_close, add_ka
150KAL 1.1 close 1.1 SCL del_close
151KAL 1.1 both 1.0 SCL del_close
Willy Tarreau60466522010-01-18 19:08:45 +0100152KAL 1.1 both 1.1 SCL del_ka, del_close
Willy Tarreau116f91e2010-01-17 11:43:59 +0100153
154SCL 1.0 - any SCL add_ka
155SCL 1.0 ka any SCL -
156SCL 1.0 close any SCL del_close, add_ka
157SCL 1.0 both any SCL del_close
158
159SCL 1.1 - 1.0 SCL add_ka
160SCL 1.1 - 1.1 SCL -
161SCL 1.1 ka 1.0 SCL -
162SCL 1.1 ka 1.1 SCL del_ka
163SCL 1.1 close 1.0 SCL del_close, add_ka
164SCL 1.1 close 1.1 SCL del_close
165SCL 1.1 both 1.0 SCL del_close
Willy Tarreau60466522010-01-18 19:08:45 +0100166SCL 1.1 both 1.1 SCL del_ka, del_close
Willy Tarreau116f91e2010-01-17 11:43:59 +0100167
168CLO 1.0 - any CLO -
169CLO 1.0 ka any CLO del_ka
170CLO 1.0 close any CLO del_close
171CLO 1.0 both any CLO del_ka, del_close
172
173CLO 1.1 - any CLO add_close
174CLO 1.1 ka any CLO del_ka, add_close
175CLO 1.1 close any CLO -
176CLO 1.1 both any CLO del_ka
177
178=> in summary :
179 - the header operations do not depend on the initial mode, they only depend
180 on versions and current connection header(s).
181
182 - both CLO and TUN modes work similarly, they need to set a close mode on the
183 reponse. A 1.1 response will exclusively need the close header, while a 1.0
184 response will have it removed. Any keep-alive header is always removed when
185 found.
186
187 - a KAL request where the server wants to close turns into an SCL response so
188 that we release the server but still maintain the connection to the client.
189
190 - the KAL and SCL modes work the same way as we need to set keep-alive on the
191 response. So a 1.0 response will only have the keep-alive header with any
192 close header removed. A 1.1 response will have the keep-alive header added
193 for 1.0 requests and the close header removed for all requests.
194
195Note that the SCL and CLO modes will automatically cause the server connection
196to be closed at the end of the data transfer.