A/A run 45189518824 (Linux): in one run the second visit of the HTTP/3 page asked for /favicon.ico, in the other it did not. Over 14 transcripts of the day Firefox asks once per origin of a launch: in the journey on the first page of each origin (140 of 140), on no page of the other steps (0 of 980), and in the walks ?v=1 always asks while ?v=2 does not (59 and 60 of 60). Hypothesis, not proved: the goto of ?v=2 races the recording of ?v=1's favicon. - settle_visit, the one point a visit is left from: the favicon of the page's origin has been asked for and served in full (WireServer.answered_at, marked after the last byte on http1, h2 and h3), then the page reaches networkidle. Each wait has the 120 s hang guard; one that reaches it is an error of the transcript that names the visit and the missing wait. - The evidence of the transcript keeps the arrival and the end of the answer of the HTTP/3 requests, for the measure to make if this falls again. The journey is not touched. - Unit rows 3443/3444.
97 lines
5.0 KiB
Python
97 lines
5.0 KiB
Python
"""What an HTTP/3 client says, read by the lab server (``tests/_wire_capture.py``, the QUIC side of ``WireServer``), held to a real ``aioquic`` client with no browser.
|
|
|
|
The oracle compares what two engines send over QUIC: the transport parameters in the order they come, the SETTINGS frame of HTTP/3 and the order of the headers of a request.
|
|
This test makes the server read a client whose values it knows: the transport parameters aioquic sends, its SETTINGS, and a request with its pseudo-headers in the order it was
|
|
given. A server that reads none of them (an empty list, no SETTINGS, the headers sorted) is red here.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import asyncio
|
|
import ssl
|
|
|
|
import pytest
|
|
|
|
import _wire_capture as wc
|
|
|
|
pytestmark = pytest.mark.unit
|
|
|
|
|
|
async def _get(port: int) -> int:
|
|
from aioquic.asyncio import connect
|
|
from aioquic.asyncio.protocol import QuicConnectionProtocol
|
|
from aioquic.h3.connection import H3_ALPN, H3Connection
|
|
from aioquic.h3.events import DataReceived, HeadersReceived
|
|
from aioquic.quic.configuration import QuicConfiguration
|
|
|
|
class Client(QuicConnectionProtocol):
|
|
def __init__(self, *args, **kwargs) -> None:
|
|
super().__init__(*args, **kwargs)
|
|
self.http = H3Connection(self._quic)
|
|
self.status = asyncio.get_event_loop().create_future()
|
|
|
|
def quic_event_received(self, event) -> None:
|
|
for http_event in self.http.handle_event(event):
|
|
if isinstance(http_event, HeadersReceived):
|
|
self.headers = dict(http_event.headers)
|
|
elif isinstance(http_event, DataReceived) and http_event.stream_ended and not self.status.done():
|
|
self.status.set_result(int(self.headers[b":status"]))
|
|
|
|
configuration = QuicConfiguration(is_client=True, alpn_protocols=H3_ALPN, verify_mode=ssl.CERT_NONE, server_name="wire.test")
|
|
async with connect("127.0.0.1", port, configuration=configuration, create_protocol=Client) as client:
|
|
stream = client._quic.get_next_available_stream_id()
|
|
client.http.send_headers(stream, [(b":method", b"GET"), (b":scheme", b"https"), (b":authority", b"wire.test"), (b":path", b"/wire.css"),
|
|
(b"user-agent", b"a-test"), (b"accept", b"text/css"), (b"x-last", b"z")], end_stream=True)
|
|
client.transmit()
|
|
return await asyncio.wait_for(client.status, 60)
|
|
|
|
|
|
def test_a_quic_client_is_recorded_transport_parameters_settings_and_the_order_of_a_request():
|
|
with wc.WireServer(h3=True) as server:
|
|
assert asyncio.run(_get(server.port)) == 200
|
|
snapshot = server.snapshot()
|
|
(connection,) = snapshot["quic"]
|
|
assert connection["alpn"] == "h3"
|
|
parameters = connection["transport_parameters"]
|
|
names = [p.get("name") or p["id"] for p in parameters]
|
|
assert names, "no transport parameter was read"
|
|
assert "initial_max_data" in names and "initial_max_streams_bidi" in names and "max_idle_timeout" in names
|
|
assert ("initial_source_connection_id" in names) and all("value" not in p for p in parameters if p.get("name") == "initial_source_connection_id")
|
|
by_name = {p["name"]: p for p in parameters if "name" in p}
|
|
assert by_name["initial_max_data"]["value"] > 0
|
|
settings = dict(connection["h3_settings"])
|
|
assert "QPACK_MAX_TABLE_CAPACITY" in settings and "QPACK_BLOCKED_STREAMS" in settings
|
|
(request,) = connection["requests"]
|
|
assert request["pseudo_order"] == [":method", ":scheme", ":authority", ":path"]
|
|
assert request["header_names"] == ["user-agent", "accept", "x-last"]
|
|
assert [n for n, _v in request["headers"]][:4] == [":method", ":scheme", ":authority", ":path"]
|
|
|
|
|
|
def test_an_http3_request_is_answered_in_full_only_when_the_datagrams_of_its_answer_have_left_and_it_keeps_the_moment_it_arrived():
|
|
import threading
|
|
import time
|
|
|
|
from _waits import wait_until
|
|
|
|
release = threading.Event()
|
|
|
|
def responder(request):
|
|
release.wait(60) # the loop of the QUIC server is held here, which is what a request that has arrived and is not yet answered is
|
|
return wc.default_responder(request)
|
|
|
|
with wc.WireServer(h3=True, responder=responder) as server:
|
|
statuses = []
|
|
thread = threading.Thread(target=lambda: statuses.append(asyncio.run(_get(server.port))), daemon=True)
|
|
thread.start()
|
|
try:
|
|
assert wait_until(lambda: any(q["requests"] for q in server.snapshot()["quic"]), 30, lambda: time.sleep(0.01)), "the request never arrived"
|
|
assert server.answered_at("/wire.css") is None, "the request has arrived and its answer is not written"
|
|
finally:
|
|
release.set()
|
|
thread.join(60)
|
|
assert statuses == [200]
|
|
assert wait_until(lambda: server.answered_at("/wire.css") is not None, 30, lambda: time.sleep(0.01)), "the answer was never marked as written"
|
|
written = server.answered_at("/wire.css")
|
|
(connection,) = server.snapshot()["quic"]
|
|
(request,) = connection["requests"]
|
|
assert isinstance(written, float) and request["t"] <= written == request["written_t"]
|