Commit f11fc7b
Skip body draining when Connection: close is set (#546)
* Skip body draining when Connection: close is set
When a response includes a Connection: close header (either from the
request or response), there's no need to drain the unread request body
since the connection will be closed anyway and won't be reused.
This change adds a clause to ensure_completed that returns early when
keepalive is false, avoiding the body read timeout that would otherwise
occur when returning early errors for requests with large bodies.
This is particularly useful for scenarios where:
- A client sends a request with a large body (e.g., file upload)
- The server returns an error early (e.g., 401 Unauthorized)
- The server sets Connection: close to signal the connection will end
Previously, Bandit would wait for the body read timeout before closing
the connection. Now it closes immediately.
* Minor formatting change to please the linter
---------
Co-authored-by: Mat Trudel <[email protected]>1 parent 4a24bda commit f11fc7b
File tree
2 files changed
+40
-0
lines changed- lib/bandit/http1
- test/bandit/http1
2 files changed
+40
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
429 | 429 | | |
430 | 430 | | |
431 | 431 | | |
| 432 | + | |
432 | 433 | | |
433 | 434 | | |
434 | 435 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
242 | 242 | | |
243 | 243 | | |
244 | 244 | | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
245 | 284 | | |
246 | 285 | | |
247 | 286 | | |
| |||
0 commit comments