Willy Tarreau | 116f91e | 2010-01-17 11:43:59 +0100 | [diff] [blame] | 1 | 2010/01/16 - Connection header adjustments depending on the transaction mode. |
| 2 | |
| 3 | |
| 4 | HTTP 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 | |
| 12 | When only WANT_TUN is set, nothing is changed nor analysed, so for commodity |
| 13 | below, we'll refer to WANT_TUN+httpclose as WANT_TUN. |
| 14 | |
| 15 | The 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 | |
| 21 | 1) 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 | |
| 28 | Note that option httpclose combined with any other option is equivalent to |
| 29 | forceclose. |
| 30 | |
| 31 | |
| 32 | 2) Adjusting the request mode once the request is parsed |
| 33 | |
| 34 | If we cannot determine the body length from the headers, we set the mode to CLO |
| 35 | but later we'll switch to tunnel mode once forwarding the body. That way, all |
| 36 | parties are informed of the correct mode. |
| 37 | |
| 38 | Depending on the request version and request Connection header, we may have to |
| 39 | adjust the current transaction mode and to update the connection header. |
| 40 | |
| 41 | mode req_ver req_hdr new_mode hdr_change |
| 42 | TUN 1.0 - TUN - |
| 43 | TUN 1.0 ka TUN del_ka |
| 44 | TUN 1.0 close TUN del_close |
| 45 | TUN 1.0 both TUN del_ka, del_close |
| 46 | |
| 47 | TUN 1.1 - TUN add_close |
| 48 | TUN 1.1 ka TUN del_ka, add_close |
| 49 | TUN 1.1 close TUN - |
| 50 | TUN 1.1 both TUN del_ka |
| 51 | |
| 52 | KAL 1.0 - CLO - |
| 53 | KAL 1.0 ka KAL - |
| 54 | KAL 1.0 close CLO del_close |
| 55 | KAL 1.0 both CLO del_ka, del_close |
| 56 | |
| 57 | KAL 1.1 - KAL - |
| 58 | KAL 1.1 ka KAL del_ka |
| 59 | KAL 1.1 close CLO - |
| 60 | KAL 1.1 both CLO del_ka |
| 61 | |
| 62 | SCL 1.0 - CLO - |
| 63 | SCL 1.0 ka SCL del_ka |
| 64 | SCL 1.0 close CLO del_close |
| 65 | SCL 1.0 both CLO del_ka, del_close |
| 66 | |
| 67 | SCL 1.1 - SCL add_close |
| 68 | SCL 1.1 ka SCL del_ka, add_close |
| 69 | SCL 1.1 close CLO - |
| 70 | SCL 1.1 both CLO del_ka |
| 71 | |
| 72 | CLO 1.0 - CLO - |
| 73 | CLO 1.0 ka CLO del_ka |
Willy Tarreau | 6046652 | 2010-01-18 19:08:45 +0100 | [diff] [blame] | 74 | CLO 1.0 close CLO del_close |
Willy Tarreau | 116f91e | 2010-01-17 11:43:59 +0100 | [diff] [blame] | 75 | CLO 1.0 both CLO del_ka, del_close |
| 76 | |
| 77 | CLO 1.1 - CLO add_close |
| 78 | CLO 1.1 ka CLO del_ka, add_close |
| 79 | CLO 1.1 close CLO - |
| 80 | CLO 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 | |
| 98 | Note that the request processing is performed in two passes, one with the |
| 99 | frontend's config and a second one with the backend's config. It is only |
| 100 | possible to "raise" the mode between them, so during the second pass, we have |
| 101 | no reason to re-add a header that we previously removed. As an exception, the |
| 102 | TUN mode is converted to CLO once combined because in fact it's an httpclose |
| 103 | option 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 | |
| 117 | 3) Adjusting the final mode once the response is parsed |
| 118 | |
| 119 | This part becomes trickier. It is possible that the server responds with a |
| 120 | version that the client does not necessarily understand. Obviously, 1.1 clients |
| 121 | are asusmed to understand 1.0 responses. The problematic case is a 1.0 client |
| 122 | receiving a 1.1 response without any Connection header. Some 1.0 clients might |
| 123 | know that in 1.1 this means "keep-alive" while others might ignore the version |
| 124 | and assume a "close". Since we know the version on both sides, we may have to |
| 125 | adjust some responses to remove any ambiguous case. That's the reason why the |
| 126 | following table considers both the request and the response version. If the |
| 127 | response length cannot be determined, we switch to CLO mode. |
| 128 | |
| 129 | mode res_ver res_hdr req_ver new_mode hdr_change |
| 130 | TUN 1.0 - any TUN - |
| 131 | TUN 1.0 ka any TUN del_ka |
| 132 | TUN 1.0 close any TUN del_close |
| 133 | TUN 1.0 both any TUN del_ka, del_close |
| 134 | |
| 135 | TUN 1.1 - any TUN add_close |
| 136 | TUN 1.1 ka any TUN del_ka, add_close |
| 137 | TUN 1.1 close any TUN - |
| 138 | TUN 1.1 both any TUN del_ka |
| 139 | |
| 140 | KAL 1.0 - any SCL add_ka |
| 141 | KAL 1.0 ka any KAL - |
| 142 | KAL 1.0 close any SCL del_close, add_ka |
| 143 | KAL 1.0 both any SCL del_close |
| 144 | |
| 145 | KAL 1.1 - 1.0 KAL add_ka |
| 146 | KAL 1.1 - 1.1 KAL - |
| 147 | KAL 1.1 ka 1.0 KAL - |
| 148 | KAL 1.1 ka 1.1 KAL del_ka |
| 149 | KAL 1.1 close 1.0 SCL del_close, add_ka |
| 150 | KAL 1.1 close 1.1 SCL del_close |
| 151 | KAL 1.1 both 1.0 SCL del_close |
Willy Tarreau | 6046652 | 2010-01-18 19:08:45 +0100 | [diff] [blame] | 152 | KAL 1.1 both 1.1 SCL del_ka, del_close |
Willy Tarreau | 116f91e | 2010-01-17 11:43:59 +0100 | [diff] [blame] | 153 | |
| 154 | SCL 1.0 - any SCL add_ka |
| 155 | SCL 1.0 ka any SCL - |
| 156 | SCL 1.0 close any SCL del_close, add_ka |
| 157 | SCL 1.0 both any SCL del_close |
| 158 | |
| 159 | SCL 1.1 - 1.0 SCL add_ka |
| 160 | SCL 1.1 - 1.1 SCL - |
| 161 | SCL 1.1 ka 1.0 SCL - |
| 162 | SCL 1.1 ka 1.1 SCL del_ka |
| 163 | SCL 1.1 close 1.0 SCL del_close, add_ka |
| 164 | SCL 1.1 close 1.1 SCL del_close |
| 165 | SCL 1.1 both 1.0 SCL del_close |
Willy Tarreau | 6046652 | 2010-01-18 19:08:45 +0100 | [diff] [blame] | 166 | SCL 1.1 both 1.1 SCL del_ka, del_close |
Willy Tarreau | 116f91e | 2010-01-17 11:43:59 +0100 | [diff] [blame] | 167 | |
| 168 | CLO 1.0 - any CLO - |
| 169 | CLO 1.0 ka any CLO del_ka |
| 170 | CLO 1.0 close any CLO del_close |
| 171 | CLO 1.0 both any CLO del_ka, del_close |
| 172 | |
| 173 | CLO 1.1 - any CLO add_close |
| 174 | CLO 1.1 ka any CLO del_ka, add_close |
| 175 | CLO 1.1 close any CLO - |
| 176 | CLO 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 |
Joseph Herlant | 02cedc4 | 2018-11-13 19:45:17 -0800 | [diff] [blame] | 183 | response. A 1.1 response will exclusively need the close header, while a 1.0 |
Willy Tarreau | 116f91e | 2010-01-17 11:43:59 +0100 | [diff] [blame] | 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 | |
| 195 | Note that the SCL and CLO modes will automatically cause the server connection |
| 196 | to be closed at the end of the data transfer. |