|
35 | 35 | ] |
36 | 36 | ) |
37 | 37 |
|
| 38 | +CONNECTION_CLOSE_REQUEST = b"\r\n".join( |
| 39 | + [b"GET / HTTP/1.1", b"Host: example.org", b"Connection: close", b"", b""] |
| 40 | +) |
| 41 | + |
38 | 42 | LARGE_POST_REQUEST = b"\r\n".join( |
39 | 43 | [ |
40 | 44 | b"POST / HTTP/1.1", |
@@ -936,3 +940,29 @@ async def test_huge_headers_h11_max_incomplete(): |
936 | 940 | await protocol.loop.run_one() |
937 | 941 | assert b"HTTP/1.1 200 OK" in protocol.transport.buffer |
938 | 942 | assert b"Hello, world" in protocol.transport.buffer |
| 943 | + |
| 944 | + |
| 945 | +@pytest.mark.anyio |
| 946 | +@pytest.mark.parametrize( |
| 947 | + "protocol_cls,close_header", |
| 948 | + ( |
| 949 | + pytest.param( |
| 950 | + HttpToolsProtocol, |
| 951 | + b"connection: close", |
| 952 | + marks=pytest.mark.skipif( |
| 953 | + HttpToolsProtocol is None, reason="httptools is not installed" |
| 954 | + ), |
| 955 | + ), |
| 956 | + (H11Protocol, b"Connection: close"), |
| 957 | + ), |
| 958 | +) |
| 959 | +async def test_return_close_header(protocol_cls, close_header: bytes): |
| 960 | + app = Response("Hello, world", media_type="text/plain") |
| 961 | + |
| 962 | + protocol = get_connected_protocol(app, protocol_cls) |
| 963 | + protocol.data_received(CONNECTION_CLOSE_REQUEST) |
| 964 | + await protocol.loop.run_one() |
| 965 | + assert b"HTTP/1.1 200 OK" in protocol.transport.buffer |
| 966 | + assert b"content-type: text/plain" in protocol.transport.buffer |
| 967 | + assert b"content-length: 12" in protocol.transport.buffer |
| 968 | + assert close_header in protocol.transport.buffer |
0 commit comments