File tree 4 files changed +58
-2
lines changed
4 files changed +58
-2
lines changed Original file line number Diff line number Diff line change @@ -43,6 +43,7 @@ class HTTPConnectionState(enum.IntEnum):
43
43
44
44
class AsyncHTTP11Connection (AsyncConnectionInterface ):
45
45
READ_NUM_BYTES = 64 * 1024
46
+ MAX_INCOMPLETE_EVENT_SIZE = 100 * 1024
46
47
47
48
def __init__ (
48
49
self ,
@@ -57,7 +58,10 @@ def __init__(
57
58
self ._state = HTTPConnectionState .NEW
58
59
self ._state_lock = AsyncLock ()
59
60
self ._request_count = 0
60
- self ._h11_state = h11 .Connection (our_role = h11 .CLIENT )
61
+ self ._h11_state = h11 .Connection (
62
+ our_role = h11 .CLIENT ,
63
+ max_incomplete_event_size = self .MAX_INCOMPLETE_EVENT_SIZE ,
64
+ )
61
65
62
66
async def handle_async_request (self , request : Request ) -> Response :
63
67
if not self .can_handle_request (request .url .origin ):
Original file line number Diff line number Diff line change @@ -43,6 +43,7 @@ class HTTPConnectionState(enum.IntEnum):
43
43
44
44
class HTTP11Connection (ConnectionInterface ):
45
45
READ_NUM_BYTES = 64 * 1024
46
+ MAX_INCOMPLETE_EVENT_SIZE = 100 * 1024
46
47
47
48
def __init__ (
48
49
self ,
@@ -57,7 +58,10 @@ def __init__(
57
58
self ._state = HTTPConnectionState .NEW
58
59
self ._state_lock = Lock ()
59
60
self ._request_count = 0
60
- self ._h11_state = h11 .Connection (our_role = h11 .CLIENT )
61
+ self ._h11_state = h11 .Connection (
62
+ our_role = h11 .CLIENT ,
63
+ max_incomplete_event_size = self .MAX_INCOMPLETE_EVENT_SIZE ,
64
+ )
61
65
62
66
def handle_request (self , request : Request ) -> Response :
63
67
if not self .can_handle_request (request .url .origin ):
Original file line number Diff line number Diff line change @@ -310,3 +310,27 @@ async def test_http11_early_hints():
310
310
)
311
311
assert response .status == 200
312
312
assert response .content == b"<html>Hello, world! ...</html>"
313
+
314
+
315
+ @pytest .mark .anyio
316
+ async def test_http11_header_sub_100kb ():
317
+ """
318
+ A connection should be able to handle a http header size up to 100kB.
319
+ """
320
+ origin = Origin (b"https" , b"example.com" , 443 )
321
+ stream = AsyncMockStream (
322
+ [
323
+ b"HTTP/1.1 200 OK\r \n " , # 17
324
+ b"Content-Type: plain/text\r \n " , # 43
325
+ b"Cookie: " + b"x" * (100 * 1024 - 72 ) + b"\r \n " , # 102381
326
+ b"Content-Length: 0\r \n " , # 102400
327
+ b"\r \n " ,
328
+ b"" ,
329
+ ]
330
+ )
331
+ async with AsyncHTTP11Connection (
332
+ origin = origin , stream = stream , keepalive_expiry = 5.0
333
+ ) as conn :
334
+ response = await conn .request ("GET" , "https://example.com/" )
335
+ assert response .status == 200
336
+ assert response .content == b""
Original file line number Diff line number Diff line change @@ -310,3 +310,27 @@ def test_http11_early_hints():
310
310
)
311
311
assert response .status == 200
312
312
assert response .content == b"<html>Hello, world! ...</html>"
313
+
314
+
315
+
316
+ def test_http11_header_sub_100kb ():
317
+ """
318
+ A connection should be able to handle a http header size up to 100kB.
319
+ """
320
+ origin = Origin (b"https" , b"example.com" , 443 )
321
+ stream = MockStream (
322
+ [
323
+ b"HTTP/1.1 200 OK\r \n " , # 17
324
+ b"Content-Type: plain/text\r \n " , # 43
325
+ b"Cookie: " + b"x" * (100 * 1024 - 72 ) + b"\r \n " , # 102381
326
+ b"Content-Length: 0\r \n " , # 102400
327
+ b"\r \n " ,
328
+ b"" ,
329
+ ]
330
+ )
331
+ with HTTP11Connection (
332
+ origin = origin , stream = stream , keepalive_expiry = 5.0
333
+ ) as conn :
334
+ response = conn .request ("GET" , "https://example.com/" )
335
+ assert response .status == 200
336
+ assert response .content == b""
You can’t perform that action at this time.
0 commit comments