Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_handle_qpack_decoder_duplicate(self):
"""
We must only receive a single QPACK decoder stream.
"""
quic_client = FakeQuicConnection(
configuration=QuicConfiguration(is_client=True)
)
h3_client = H3Connection(quic_client)
# receive a first decoder stream
h3_client.handle_event(
StreamDataReceived(
stream_id=11,
data=encode_uint_var(StreamType.QPACK_DECODER),
end_stream=False,
)
)
# receive a second decoder stream
h3_client.handle_event(
StreamDataReceived(
stream_id=15,
data=encode_uint_var(StreamType.QPACK_DECODER),
end_stream=False,
def test_handle_request_frame_headers_after_trailers(self):
"""
We should not receive HEADERS after receiving trailers.
"""
quic_client = FakeQuicConnection(
configuration=QuicConfiguration(is_client=True)
)
quic_server = FakeQuicConnection(
configuration=QuicConfiguration(is_client=False)
)
h3_client = H3Connection(quic_client)
h3_server = H3Connection(quic_server)
stream_id = quic_client.get_next_available_stream_id()
h3_client.send_headers(
stream_id=stream_id,
headers=[
(b":method", b"GET"),
(b":scheme", b"https"),
(b":authority", b"localhost"),
(b":path", b"/"),
],
)
h3_client.send_headers(
stream_id=stream_id, headers=[(b"x-some-trailer", b"foo")], end_stream=True
)
h3_transfer(quic_client, h3_server)
def test_uni_stream_grease(self):
with client_and_server(
client_options={"alpn_protocols": H3_ALPN},
server_options={"alpn_protocols": H3_ALPN},
) as (quic_client, quic_server):
h3_server = H3Connection(quic_server)
quic_client.send_stream_data(
14, b"\xff\xff\xff\xff\xff\xff\xff\xfeGREASE is the word"
)
self.assertEqual(h3_transfer(quic_client, h3_server), [])
def test_handle_request_frame_bad_headers(self):
"""
We should not receive HEADERS which cannot be decoded.
"""
quic_server = FakeQuicConnection(
configuration=QuicConfiguration(is_client=False)
)
h3_server = H3Connection(quic_server)
h3_server.handle_event(
StreamDataReceived(
stream_id=0, data=encode_frame(FrameType.HEADERS, b""), end_stream=False
)
)
self.assertEqual(
quic_server.closed, (ErrorCode.HTTP_QPACK_DECOMPRESSION_FAILED, "")
)
def test_request(self):
with client_and_server(
client_options={"alpn_protocols": H3_ALPN},
server_options={"alpn_protocols": H3_ALPN},
) as (quic_client, quic_server):
h3_client = H3Connection(quic_client)
h3_server = H3Connection(quic_server)
# make first request
self._make_request(h3_client, h3_server)
# make second request
self._make_request(h3_client, h3_server)
# make third request -> dynamic table
self._make_request(h3_client, h3_server)
def test_blocked_stream(self):
quic_client = FakeQuicConnection(
configuration=QuicConfiguration(is_client=True)
)
h3_client = H3Connection(quic_client)
h3_client.handle_event(
StreamDataReceived(
stream_id=3,
data=binascii.unhexlify(
"0004170150000680020000074064091040bcc0000000faceb00c"
),
end_stream=False,
)
)
h3_client.handle_event(
StreamDataReceived(stream_id=7, data=b"\x02", end_stream=False)
)
h3_client.handle_event(
StreamDataReceived(stream_id=11, data=b"\x03", end_stream=False)
)
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._http: Optional[HttpConnection] = None
self._request_events: Dict[int, Deque[H3Event]] = {}
self._request_waiter: Dict[int, asyncio.Future[Deque[H3Event]]] = {}
if self._quic.configuration.alpn_protocols[0].startswith("hq-"):
self._http = H0Connection(self._quic)
else:
self._http = H3Connection(self._quic)
self._push = {}
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.pushes: Dict[int, Deque[H3Event]] = {}
self._http: Optional[HttpConnection] = None
self._request_events: Dict[int, Deque[H3Event]] = {}
self._request_waiter: Dict[int, asyncio.Future[Deque[H3Event]]] = {}
self._websockets: Dict[int, WebSocket] = {}
if self._quic.configuration.alpn_protocols[0].startswith("hq-"):
self._http = H0Connection(self._quic)
else:
self._http = H3Connection(self._quic)
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._http = H3Connection(self._quic)
self._request_events: Dict[int, Deque[H3Event]] = {}
self._request_waiter: Dict[int, asyncio.Future[Deque[H3Event]]] = {}
"query_string": query_string,
"raw_path": raw_path,
"root_path": "",
"scheme": "wss",
"subprotocols": subprotocols,
"type": "websocket",
}
handler = WebSocketHandler(
connection=self._http,
scope=scope,
stream_id=event.stream_id,
transmit=self.transmit,
)
else:
extensions: Dict[str, Dict] = {}
if isinstance(self._http, H3Connection):
extensions["http.response.push"] = {}
scope = {
"client": client,
"extensions": extensions,
"headers": headers,
"http_version": http_version,
"method": method,
"path": path,
"query_string": query_string,
"raw_path": raw_path,
"root_path": "",
"scheme": "https",
"type": "http",
}
handler = HttpRequestHandler(
authority=authority,