diff --git a/examples/http3_client.py b/examples/http3_client.py index ecd9df8d..36bb4202 100644 --- a/examples/http3_client.py +++ b/examples/http3_client.py @@ -425,7 +425,7 @@ async def main( # process http pushes process_http_pushes(client=client, include=include, output_dir=output_dir) - client._quic.close(error_code=ErrorCode.H3_NO_ERROR) + client.close(error_code=ErrorCode.H3_NO_ERROR) if __name__ == "__main__": diff --git a/src/aioquic/asyncio/protocol.py b/src/aioquic/asyncio/protocol.py index 3cbc18fb..9e530ae0 100644 --- a/src/aioquic/asyncio/protocol.py +++ b/src/aioquic/asyncio/protocol.py @@ -3,6 +3,7 @@ from ..quic import events from ..quic.connection import NetworkAddress, QuicConnection +from ..quic.packet import QuicErrorCode QuicConnectionIdHandler = Callable[[bytes], None] QuicStreamHandler = Callable[[asyncio.StreamReader, asyncio.StreamWriter], None] @@ -44,11 +45,23 @@ def change_connection_id(self) -> None: self._quic.change_connection_id() self.transmit() - def close(self) -> None: + def close( + self, + error_code: int = QuicErrorCode.NO_ERROR, + reason_phrase: str = "", + ) -> None: """ Close the connection. + + :param error_code: An error code indicating why the connection is + being closed. + :param reason_phrase: A human-readable explanation of why the + connection is being closed. """ - self._quic.close() + self._quic.close( + error_code=error_code, + reason_phrase=reason_phrase, + ) self.transmit() def connect(self, addr: NetworkAddress) -> None: