File: 0001-Bugfix-only-recycle-a-HTTP-1.1-connection-if-client-.patch

package info (click to toggle)
hypercorn 0.13.2-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 896 kB
  • sloc: python: 6,858; makefile: 18
file content (34 lines) | stat: -rw-r--r-- 1,403 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
From: pgjones <philip.graham.jones@googlemail.com>
Date: Mon, 27 Dec 2021 18:12:27 +0000
Subject: Bugfix only recycle a HTTP/1.1 connection if client is DONE

This will close rather than recycle a connection if the client is
still sending a body when the server is done recycling.

It is feasible for the server to wait for the client to finish sending
however this solution prevents a client slowly sending a body to the
server in an attempt to tie up server resources.

Origin: upstream, https://gitlab.com/pgjones/hypercorn/-/commit/13ef92a03fdcddd3f5b71b9b3450042a07e9556d
Bug: https://gitlab.com/pgjones/hypercorn/-/issues/219
---
 src/hypercorn/protocol/h11.py | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/hypercorn/protocol/h11.py b/src/hypercorn/protocol/h11.py
index 748a615..c8636bf 100755
--- a/src/hypercorn/protocol/h11.py
+++ b/src/hypercorn/protocol/h11.py
@@ -244,7 +244,11 @@ class H11Protocol:
 
     async def _maybe_recycle(self) -> None:
         await self._close_stream()
-        if not self.context.terminated and self.connection.our_state is h11.DONE:
+        if (
+            not self.context.terminated
+            and self.connection.our_state is h11.DONE
+            and self.connection.their_state is h11.DONE
+        ):
             try:
                 self.connection.start_next_cycle()
             except h11.LocalProtocolError: