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_connect(self):
with client_and_server(
client_options={"alpn_protocols": H0_ALPN},
server_options={"alpn_protocols": H0_ALPN},
) as (quic_client, quic_server):
h0_client = H0Connection(quic_client)
h0_server = H0Connection(quic_server)
# send request
stream_id = quic_client.get_next_available_stream_id()
h0_client.send_headers(
stream_id=stream_id,
headers=[
(b":method", b"GET"),
(b":scheme", b"https"),
(b":authority", b"localhost"),
(b":path", b"/"),
],
)
h0_client.send_data(stream_id=stream_id, data=b"", end_stream=True)
# receive request
events = h0_transfer(quic_client, h0_server)
def test_headers_only(self):
with client_and_server(
client_options={"alpn_protocols": H0_ALPN},
server_options={"alpn_protocols": H0_ALPN},
) as (quic_client, quic_server):
h0_client = H0Connection(quic_client)
h0_server = H0Connection(quic_server)
# send request
stream_id = quic_client.get_next_available_stream_id()
h0_client.send_headers(
stream_id=stream_id,
headers=[
(b":method", b"HEAD"),
(b":scheme", b"https"),
(b":authority", b"localhost"),
(b":path", b"/"),
],
end_stream=True,
)
# receive request
def test_headers_only(self):
with client_and_server(
client_options={"alpn_protocols": H0_ALPN},
server_options={"alpn_protocols": H0_ALPN},
) as (quic_client, quic_server):
h0_client = H0Connection(quic_client)
h0_server = H0Connection(quic_server)
# send request
stream_id = quic_client.get_next_available_stream_id()
h0_client.send_headers(
stream_id=stream_id,
headers=[
(b":method", b"HEAD"),
(b":scheme", b"https"),
(b":authority", b"localhost"),
(b":path", b"/"),
],
end_stream=True,
)
# receive request
events = h0_transfer(quic_client, h0_server)
def test_connect(self):
with client_and_server(
client_options={"alpn_protocols": H0_ALPN},
server_options={"alpn_protocols": H0_ALPN},
) as (quic_client, quic_server):
h0_client = H0Connection(quic_client)
h0_server = H0Connection(quic_server)
# send request
stream_id = quic_client.get_next_available_stream_id()
h0_client.send_headers(
stream_id=stream_id,
headers=[
(b":method", b"GET"),
(b":scheme", b"https"),
(b":authority", b"localhost"),
(b":path", b"/"),
],
)
h0_client.send_data(stream_id=stream_id, data=b"", end_stream=True)
# receive request
H3Event,
HeadersReceived,
PushPromiseReceived,
)
from aioquic.quic.configuration import QuicConfiguration
from aioquic.quic.events import QuicEvent
from aioquic.quic.logger import QuicLogger
try:
import uvloop
except ImportError:
uvloop = None
logger = logging.getLogger("client")
HttpConnection = Union[H0Connection, H3Connection]
USER_AGENT = "aioquic/" + aioquic.__version__
class URL:
def __init__(self, url: str):
parsed = urlparse(url)
self.authority = parsed.netloc
self.full_path = parsed.path
if parsed.query:
self.full_path += "?" + parsed.query
self.scheme = parsed.scheme
class HttpRequest:
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)
from aioquic.asyncio.protocol import QuicConnectionProtocol
from aioquic.h0.connection import H0_ALPN, H0Connection
from aioquic.h3.connection import H3_ALPN, H3Connection
from aioquic.h3.events import DataReceived, H3Event, HeadersReceived, PushPromiseReceived
from aioquic.quic.configuration import QuicConfiguration
from aioquic.quic.events import QuicEvent
from aioquic.quic.logger import QuicLogger
try:
import uvloop
except ImportError:
uvloop = None
logger = logging.getLogger("client")
HttpConnection = Union[H0Connection, H3Connection]
class URL:
def __init__(self, url: str):
parsed = urlparse(url)
self.authority = parsed.netloc
self.full_path = parsed.path
if parsed.query:
self.full_path += "?" + parsed.query
self.scheme = parsed.scheme
class HttpRequest:
def __init__(
self, method: str, url: URL, content: bytes = b"", headers: Dict = {}, allow_push: bool = True
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 = {}
from aioquic.h0.connection import H0_ALPN, H0Connection
from aioquic.h3.connection import H3_ALPN, H3Connection
from aioquic.h3.events import DataReceived, H3Event, HeadersReceived
from aioquic.h3.exceptions import NoAvailablePushIDError
from aioquic.quic.configuration import QuicConfiguration
from aioquic.quic.events import DatagramFrameReceived, ProtocolNegotiated, QuicEvent
from aioquic.quic.logger import QuicLogger, QuicLoggerTrace
from aioquic.tls import SessionTicket
try:
import uvloop
except ImportError:
uvloop = None
AsgiApplication = Callable
HttpConnection = Union[H0Connection, H3Connection]
SERVER_NAME = "aioquic/" + aioquic.__version__
class HttpRequestHandler:
def __init__(
self,
*,
authority: bytes,
connection: HttpConnection,
protocol: QuicConnectionProtocol,
scope: Dict,
stream_ended: bool,
stream_id: int,
transmit: Callable[[], None],
):
def quic_event_received(self, event: QuicEvent):
if isinstance(event, ProtocolNegotiated):
if event.alpn_protocol.startswith("h3-"):
self._http = H3Connection(self._quic)
elif event.alpn_protocol.startswith("hq-"):
self._http = H0Connection(self._quic)
elif isinstance(event, DatagramFrameReceived):
if event.data == b"quack":
self._quic.send_datagram_frame(b"quack-ack")
# Â pass event to the HTTP layer
if self._http is not None:
for http_event in self._http.handle_event(event):
self.http_event_received(http_event)