| 1 |
import argparse |
| 2 |
import asyncio |
| 3 |
import logging |
| 4 |
import os |
| 5 |
import pickle |
| 6 |
import ssl |
| 7 |
import time |
| 8 |
from collections import deque |
| 9 |
from typing import BinaryIO, Callable, Deque, Optional, Union, cast |
| 10 |
from urllib.parse import urlparse |
| 11 |
|
| 12 |
import aioquic |
| 13 |
import wsproto |
| 14 |
import wsproto.events |
| 15 |
from aioquic.asyncio.client import connect |
| 16 |
from aioquic.asyncio.protocol import QuicConnectionProtocol |
| 17 |
from aioquic.h0.connection import H0_ALPN, H0Connection |
| 18 |
from aioquic.h3.connection import H3_ALPN, ErrorCode, H3Connection |
| 19 |
from aioquic.h3.events import ( |
| 20 |
DataReceived, |
| 21 |
H3Event, |
| 22 |
HeadersReceived, |
| 23 |
PushPromiseReceived, |
| 24 |
) |
| 25 |
from aioquic.quic.configuration import QuicConfiguration |
| 26 |
from aioquic.quic.events import QuicEvent |
| 27 |
from aioquic.quic.logger import QuicFileLogger |
| 28 |
from aioquic.quic.packet import QuicProtocolVersion |
| 29 |
from aioquic.tls import CipherSuite, SessionTicket |
| 30 |
|
| 31 |
try: |
| 32 |
import uvloop |
| 33 |
except ImportError: |
| 34 |
uvloop = None |
| 35 |
|
| 36 |
logger = logging.getLogger("client") |
| 37 |
|
| 38 |
HttpConnection = Union[H0Connection, H3Connection] |
| 39 |
|
| 40 |
USER_AGENT = "aioquic/" + aioquic.__version__ |
| 41 |
|
| 42 |
|
| 43 |
class URL: |
| 44 |
def __init__(self, url: str) -> None: |
| 45 |
parsed = urlparse(url) |
| 46 |
|
| 47 |
self.authority = parsed.netloc |
| 48 |
self.full_path = parsed.path or "/" |
| 49 |
if parsed.query: |
| 50 |
self.full_path += "?" + parsed.query |
| 51 |
self.scheme = parsed.scheme |
| 52 |
|
| 53 |
|
| 54 |
class HttpRequest: |
| 55 |
def __init__( |
| 56 |
self, |
| 57 |
method: str, |
| 58 |
url: URL, |
| 59 |
content: bytes = b"", |
| 60 |
headers: Optional[dict] = None, |
| 61 |
) -> None: |
| 62 |
if headers is None: |
| 63 |
headers = {} |
| 64 |
|
| 65 |
self.content = content |
| 66 |
self.headers = headers |
| 67 |
self.method = method |
| 68 |
self.url = url |
| 69 |
|
| 70 |
|
| 71 |
class WebSocket: |
| 72 |
def __init__( |
| 73 |
self, http: HttpConnection, stream_id: int, transmit: Callable[[], None] |
| 74 |
) -> None: |
| 75 |
self.http = http |
| 76 |
self.queue: asyncio.Queue[str] = asyncio.Queue() |
| 77 |
self.stream_id = stream_id |
| 78 |
self.subprotocol: Optional[str] = None |
| 79 |
self.transmit = transmit |
| 80 |
self.websocket = wsproto.Connection(wsproto.ConnectionType.CLIENT) |
| 81 |
|
| 82 |
async def close(self, code: int = 1000, reason: str = "") -> None: |
| 83 |
""" |
| 84 |
Perform the closing handshake. |
| 85 |
""" |
| 86 |
data = self.websocket.send( |
| 87 |
wsproto.events.CloseConnection(code=code, reason=reason) |
| 88 |
) |
| 89 |
self.http.send_data(stream_id=self.stream_id, data=data, end_stream=True) |
| 90 |
self.transmit() |
| 91 |
|
| 92 |
async def recv(self) -> str: |
| 93 |
""" |
| 94 |
Receive the next message. |
| 95 |
""" |
| 96 |
return await self.queue.get() |
| 97 |
|
| 98 |
async def send(self, message: str) -> None: |
| 99 |
""" |
| 100 |
Send a message. |
| 101 |
""" |
| 102 |
assert isinstance(message, str) |
| 103 |
|
| 104 |
data = self.websocket.send(wsproto.events.TextMessage(data=message)) |
| 105 |
self.http.send_data(stream_id=self.stream_id, data=data, end_stream=False) |
| 106 |
self.transmit() |
| 107 |
|
| 108 |
def http_event_received(self, event: H3Event) -> None: |
| 109 |
if isinstance(event, HeadersReceived): |
| 110 |
for header, value in event.headers: |
| 111 |
if header == b"sec-websocket-protocol": |
| 112 |
self.subprotocol = value.decode() |
| 113 |
elif isinstance(event, DataReceived): |
| 114 |
self.websocket.receive_data(event.data) |
| 115 |
|
| 116 |
for ws_event in self.websocket.events(): |
| 117 |
self.websocket_event_received(ws_event) |
| 118 |
|
| 119 |
def websocket_event_received(self, event: wsproto.events.Event) -> None: |
| 120 |
if isinstance(event, wsproto.events.TextMessage): |
| 121 |
self.queue.put_nowait(event.data) |
| 122 |
|
| 123 |
|
| 124 |
class HttpClient(QuicConnectionProtocol): |
| 125 |
def __init__(self, *args, **kwargs) -> None: |
| 126 |
super().__init__(*args, **kwargs) |
| 127 |
|
| 128 |
self.key_update = False |
| 129 |
self.pushes: dict[int, Deque[H3Event]] = {} |
| 130 |
self._http: Optional[HttpConnection] = None |
| 131 |
self._request_events: dict[int, Deque[H3Event]] = {} |
| 132 |
self._request_waiter: dict[int, asyncio.Future[Deque[H3Event]]] = {} |
| 133 |
self._websockets: dict[int, WebSocket] = {} |
| 134 |
|
| 135 |
if self._quic.configuration.alpn_protocols[0].startswith("hq-"): |
| 136 |
self._http = H0Connection(self._quic) |
| 137 |
else: |
| 138 |
self._http = H3Connection(self._quic) |
| 139 |
|
| 140 |
async def get(self, url: str, headers: Optional[dict] = None) -> Deque[H3Event]: |
| 141 |
""" |
| 142 |
Perform a GET request. |
| 143 |
""" |
| 144 |
return await self._request( |
| 145 |
HttpRequest(method="GET", url=URL(url), headers=headers) |
| 146 |
) |
| 147 |
|
| 148 |
async def post( |
| 149 |
self, url: str, data: bytes, headers: Optional[dict] = None |
| 150 |
) -> Deque[H3Event]: |
| 151 |
""" |
| 152 |
Perform a POST request. |
| 153 |
""" |
| 154 |
return await self._request( |
| 155 |
HttpRequest(method="POST", url=URL(url), content=data, headers=headers) |
| 156 |
) |
| 157 |
|
| 158 |
async def websocket( |
| 159 |
self, url: str, subprotocols: Optional[list[str]] = None |
| 160 |
) -> WebSocket: |
| 161 |
""" |
| 162 |
Open a WebSocket. |
| 163 |
""" |
| 164 |
request = HttpRequest(method="CONNECT", url=URL(url)) |
| 165 |
stream_id = self._quic.get_next_available_stream_id() |
| 166 |
websocket = WebSocket( |
| 167 |
http=self._http, stream_id=stream_id, transmit=self.transmit |
| 168 |
) |
| 169 |
|
| 170 |
self._websockets[stream_id] = websocket |
| 171 |
|
| 172 |
headers = [ |
| 173 |
(b":method", b"CONNECT"), |
| 174 |
(b":scheme", b"https"), |
| 175 |
(b":authority", request.url.authority.encode()), |
| 176 |
(b":path", request.url.full_path.encode()), |
| 177 |
(b":protocol", b"websocket"), |
| 178 |
(b"user-agent", USER_AGENT.encode()), |
| 179 |
(b"sec-websocket-version", b"13"), |
| 180 |
] |
| 181 |
if subprotocols: |
| 182 |
headers.append( |
| 183 |
(b"sec-websocket-protocol", ", ".join(subprotocols).encode()) |
| 184 |
) |
| 185 |
self._http.send_headers(stream_id=stream_id, headers=headers) |
| 186 |
|
| 187 |
self.transmit() |
| 188 |
|
| 189 |
return websocket |
| 190 |
|
| 191 |
def http_event_received(self, event: H3Event) -> None: |
| 192 |
if isinstance(event, (HeadersReceived, DataReceived)): |
| 193 |
stream_id = event.stream_id |
| 194 |
if stream_id in self._request_events: |
| 195 |
|
| 196 |
self._request_events[event.stream_id].append(event) |
| 197 |
if event.stream_ended: |
| 198 |
request_waiter = self._request_waiter.pop(stream_id) |
| 199 |
request_waiter.set_result(self._request_events.pop(stream_id)) |
| 200 |
|
| 201 |
elif stream_id in self._websockets: |
| 202 |
|
| 203 |
websocket = self._websockets[stream_id] |
| 204 |
websocket.http_event_received(event) |
| 205 |
|
| 206 |
elif event.push_id in self.pushes: |
| 207 |
|
| 208 |
self.pushes[event.push_id].append(event) |
| 209 |
|
| 210 |
|
| 211 |
if self.key_update: |
| 212 |
logger.info("Requesting key update") |
| 213 |
self.request_key_update() |
| 214 |
self.key_update = False |
| 215 |
|
| 216 |
elif isinstance(event, PushPromiseReceived): |
| 217 |
self.pushes[event.push_id] = deque() |
| 218 |
self.pushes[event.push_id].append(event) |
| 219 |
|
| 220 |
def quic_event_received(self, event: QuicEvent) -> None: |
| 221 |
r |
| 222 |
if self._http is not None: |
| 223 |
for http_event in self._http.handle_event(event): |
| 224 |
self.http_event_received(http_event) |
| 225 |
|
| 226 |
async def _request(self, request: HttpRequest) -> Deque[H3Event]: |
| 227 |
stream_id = self._quic.get_next_available_stream_id() |
| 228 |
self._http.send_headers( |
| 229 |
stream_id=stream_id, |
| 230 |
headers=[ |
| 231 |
(b":method", request.method.encode()), |
| 232 |
(b":scheme", request.url.scheme.encode()), |
| 233 |
(b":authority", request.url.authority.encode()), |
| 234 |
(b":path", request.url.full_path.encode()), |
| 235 |
(b"user-agent", USER_AGENT.encode()), |
| 236 |
] |
| 237 |
+ [(k.encode(), v.encode()) for (k, v) in request.headers.items()], |
| 238 |
end_stream=not request.content, |
| 239 |
) |
| 240 |
if request.content: |
| 241 |
self._http.send_data( |
| 242 |
stream_id=stream_id, data=request.content, end_stream=True |
| 243 |
) |
| 244 |
|
| 245 |
waiter = self._loop.create_future() |
| 246 |
self._request_events[stream_id] = deque() |
| 247 |
self._request_waiter[stream_id] = waiter |
| 248 |
self.transmit() |
| 249 |
|
| 250 |
return await asyncio.shield(waiter) |
| 251 |
|
| 252 |
|
| 253 |
async def perform_http_request( |
| 254 |
client: HttpClient, |
| 255 |
url: str, |
| 256 |
data: Optional[str], |
| 257 |
include: bool, |
| 258 |
output_dir: Optional[str], |
| 259 |
) -> None: |
| 260 |
|
| 261 |
start = time.time() |
| 262 |
if data is not None: |
| 263 |
data_bytes = data.encode() |
| 264 |
http_events = await client.post( |
| 265 |
url, |
| 266 |
data=data_bytes, |
| 267 |
headers={ |
| 268 |
"content-length": str(len(data_bytes)), |
| 269 |
"content-type": "application/x-www-form-urlencoded", |
| 270 |
}, |
| 271 |
) |
| 272 |
method = "POST" |
| 273 |
else: |
| 274 |
http_events = await client.get(url) |
| 275 |
method = "GET" |
| 276 |
elapsed = time.time() - start |
| 277 |
|
| 278 |
|
| 279 |
octets = 0 |
| 280 |
for http_event in http_events: |
| 281 |
if isinstance(http_event, DataReceived): |
| 282 |
octets += len(http_event.data) |
| 283 |
logger.info( |
| 284 |
"Response received for %s %s : %d bytes in %.1f s (%.3f Mbps)" |
| 285 |
% (method, urlparse(url).path, octets, elapsed, octets * 8 / elapsed / 1000000) |
| 286 |
) |
| 287 |
|
| 288 |
|
| 289 |
if output_dir is not None: |
| 290 |
output_path = os.path.join( |
| 291 |
output_dir, os.path.basename(urlparse(url).path) or "index.html" |
| 292 |
) |
| 293 |
with open(output_path, "wb") as output_file: |
| 294 |
write_response( |
| 295 |
http_events=http_events, include=include, output_file=output_file |
| 296 |
) |
| 297 |
|
| 298 |
|
| 299 |
def process_http_pushes( |
| 300 |
client: HttpClient, |
| 301 |
include: bool, |
| 302 |
output_dir: Optional[str], |
| 303 |
) -> None: |
| 304 |
for _, http_events in client.pushes.items(): |
| 305 |
method = "" |
| 306 |
octets = 0 |
| 307 |
path = "" |
| 308 |
for http_event in http_events: |
| 309 |
if isinstance(http_event, DataReceived): |
| 310 |
octets += len(http_event.data) |
| 311 |
elif isinstance(http_event, PushPromiseReceived): |
| 312 |
for header, value in http_event.headers: |
| 313 |
if header == b":method": |
| 314 |
method = value.decode() |
| 315 |
elif header == b":path": |
| 316 |
path = value.decode() |
| 317 |
logger.info("Push received for %s %s : %s bytes", method, path, octets) |
| 318 |
|
| 319 |
|
| 320 |
if output_dir is not None: |
| 321 |
output_path = os.path.join( |
| 322 |
output_dir, os.path.basename(path) or "index.html" |
| 323 |
) |
| 324 |
with open(output_path, "wb") as output_file: |
| 325 |
write_response( |
| 326 |
http_events=http_events, include=include, output_file=output_file |
| 327 |
) |
| 328 |
|
| 329 |
|
| 330 |
def write_response( |
| 331 |
http_events: Deque[H3Event], output_file: BinaryIO, include: bool |
| 332 |
) -> None: |
| 333 |
for http_event in http_events: |
| 334 |
if isinstance(http_event, HeadersReceived) and include: |
| 335 |
headers = b"" |
| 336 |
for k, v in http_event.headers: |
| 337 |
headers += k + b": " + v + b"\r\n" |
| 338 |
if headers: |
| 339 |
output_file.write(headers + b"\r\n") |
| 340 |
elif isinstance(http_event, DataReceived): |
| 341 |
output_file.write(http_event.data) |
| 342 |
|
| 343 |
|
| 344 |
def save_session_ticket(ticket: SessionTicket) -> None: |
| 345 |
""" |
| 346 |
Callback which is invoked by the TLS engine when a new session ticket |
| 347 |
is received. |
| 348 |
""" |
| 349 |
logger.info("New session ticket received") |
| 350 |
if args.session_ticket: |
| 351 |
with open(args.session_ticket, "wb") as fp: |
| 352 |
pickle.dump(ticket, fp) |
| 353 |
|
| 354 |
|
| 355 |
async def main( |
| 356 |
configuration: QuicConfiguration, |
| 357 |
urls: list[str], |
| 358 |
data: Optional[str], |
| 359 |
include: bool, |
| 360 |
output_dir: Optional[str], |
| 361 |
local_port: int, |
| 362 |
key_update: bool, |
| 363 |
zero_rtt: bool, |
| 364 |
) -> None: |
| 365 |
|
| 366 |
parsed = urlparse(urls[0]) |
| 367 |
assert parsed.scheme in ( |
| 368 |
"https", |
| 369 |
"wss", |
| 370 |
), "Only https:// or wss:// URLs are supported." |
| 371 |
host = parsed.hostname |
| 372 |
if parsed.port is not None: |
| 373 |
port = parsed.port |
| 374 |
else: |
| 375 |
port = 443 |
| 376 |
|
| 377 |
|
| 378 |
for i in range(1, len(urls)): |
| 379 |
_p = urlparse(urls[i]) |
| 380 |
|
| 381 |
|
| 382 |
_scheme = _p.scheme or parsed.scheme |
| 383 |
_host = _p.hostname or host |
| 384 |
_port = _p.port or port |
| 385 |
|
| 386 |
assert _scheme == parsed.scheme, "URL scheme doesn't match" |
| 387 |
assert _host == host, "URL hostname doesn't match" |
| 388 |
assert _port == port, "URL port doesn't match" |
| 389 |
|
| 390 |
|
| 391 |
_p = _p._replace(scheme=_scheme) |
| 392 |
_p = _p._replace(netloc="{}:{}".format(_host, _port)) |
| 393 |
_p = urlparse(_p.geturl()) |
| 394 |
urls[i] = _p.geturl() |
| 395 |
|
| 396 |
async with connect( |
| 397 |
host, |
| 398 |
port, |
| 399 |
configuration=configuration, |
| 400 |
create_protocol=HttpClient, |
| 401 |
session_ticket_handler=save_session_ticket, |
| 402 |
local_port=local_port, |
| 403 |
wait_connected=not zero_rtt, |
| 404 |
) as client: |
| 405 |
client = cast(HttpClient, client) |
| 406 |
client.key_update = key_update |
| 407 |
|
| 408 |
if parsed.scheme == "wss": |
| 409 |
ws = await client.websocket(urls[0], subprotocols=["chat", "superchat"]) |
| 410 |
|
| 411 |
|
| 412 |
for i in range(2): |
| 413 |
message = "Hello {}, WebSocket!".format(i) |
| 414 |
print("> " + message) |
| 415 |
await ws.send(message) |
| 416 |
|
| 417 |
message = await ws.recv() |
| 418 |
print("< " + message) |
| 419 |
|
| 420 |
await ws.close() |
| 421 |
else: |
| 422 |
|
| 423 |
coros = [ |
| 424 |
perform_http_request( |
| 425 |
client=client, |
| 426 |
url=url, |
| 427 |
data=data, |
| 428 |
include=include, |
| 429 |
output_dir=output_dir, |
| 430 |
) |
| 431 |
for url in urls |
| 432 |
] |
| 433 |
await asyncio.gather(*coros) |
| 434 |
|
| 435 |
|
| 436 |
process_http_pushes(client=client, include=include, output_dir=output_dir) |
| 437 |
client.close(error_code=ErrorCode.H3_NO_ERROR) |
| 438 |
|
| 439 |
|
| 440 |
if __name__ == "__main__": |
| 441 |
defaults = QuicConfiguration(is_client=True) |
| 442 |
|
| 443 |
parser = argparse.ArgumentParser(description="HTTP/3 client") |
| 444 |
parser.add_argument( |
| 445 |
"url", type=str, nargs="+", help="the URL to query (must be HTTPS)" |
| 446 |
) |
| 447 |
parser.add_argument( |
| 448 |
"--ca-certs", type=str, help="load CA certificates from the specified file" |
| 449 |
) |
| 450 |
parser.add_argument( |
| 451 |
"--certificate", |
| 452 |
type=str, |
| 453 |
help="load the TLS certificate from the specified file", |
| 454 |
) |
| 455 |
parser.add_argument( |
| 456 |
"--cipher-suites", |
| 457 |
type=str, |
| 458 |
help=( |
| 459 |
"only advertise the given cipher suites, e.g. `AES_256_GCM_SHA384," |
| 460 |
"CHACHA20_POLY1305_SHA256`" |
| 461 |
), |
| 462 |
) |
| 463 |
parser.add_argument( |
| 464 |
"--congestion-control-algorithm", |
| 465 |
type=str, |
| 466 |
default="reno", |
| 467 |
help="use the specified congestion control algorithm", |
| 468 |
) |
| 469 |
parser.add_argument( |
| 470 |
"-d", "--data", type=str, help="send the specified data in a POST request" |
| 471 |
) |
| 472 |
parser.add_argument( |
| 473 |
"-i", |
| 474 |
"--include", |
| 475 |
action="store_true", |
| 476 |
help="include the HTTP response headers in the output", |
| 477 |
) |
| 478 |
parser.add_argument( |
| 479 |
"--insecure", |
| 480 |
action="store_true", |
| 481 |
help="do not validate server certificate", |
| 482 |
) |
| 483 |
parser.add_argument( |
| 484 |
"--key-update", |
| 485 |
action="store_true", |
| 486 |
help="request a key update", |
| 487 |
) |
| 488 |
parser.add_argument( |
| 489 |
"--legacy-http", |
| 490 |
action="store_true", |
| 491 |
help="use HTTP/0.9", |
| 492 |
) |
| 493 |
parser.add_argument( |
| 494 |
"--max-data", |
| 495 |
type=int, |
| 496 |
help="connection-wide flow control limit (default: %d)" % defaults.max_data, |
| 497 |
) |
| 498 |
parser.add_argument( |
| 499 |
"--max-stream-data", |
| 500 |
type=int, |
| 501 |
help="per-stream flow control limit (default: %d)" % defaults.max_stream_data, |
| 502 |
) |
| 503 |
parser.add_argument( |
| 504 |
"--negotiate-v2", |
| 505 |
action="store_true", |
| 506 |
help="start with QUIC v1 and try to negotiate QUIC v2", |
| 507 |
) |
| 508 |
|
| 509 |
parser.add_argument( |
| 510 |
"--output-dir", |
| 511 |
type=str, |
| 512 |
help="write downloaded files to this directory", |
| 513 |
) |
| 514 |
parser.add_argument( |
| 515 |
"--private-key", |
| 516 |
type=str, |
| 517 |
help="load the TLS private key from the specified file", |
| 518 |
) |
| 519 |
parser.add_argument( |
| 520 |
"-q", |
| 521 |
"--quic-log", |
| 522 |
type=str, |
| 523 |
help="log QUIC events to QLOG files in the specified directory", |
| 524 |
) |
| 525 |
parser.add_argument( |
| 526 |
"-l", |
| 527 |
"--secrets-log", |
| 528 |
type=str, |
| 529 |
help="log secrets to a file, for use with Wireshark", |
| 530 |
) |
| 531 |
parser.add_argument( |
| 532 |
"-s", |
| 533 |
"--session-ticket", |
| 534 |
type=str, |
| 535 |
help="read and write session ticket from the specified file", |
| 536 |
) |
| 537 |
parser.add_argument( |
| 538 |
"-v", "--verbose", action="store_true", help="increase logging verbosity" |
| 539 |
) |
| 540 |
parser.add_argument( |
| 541 |
"--local-port", |
| 542 |
type=int, |
| 543 |
default=0, |
| 544 |
help="local port to bind for connections", |
| 545 |
) |
| 546 |
parser.add_argument( |
| 547 |
"--max-datagram-size", |
| 548 |
type=int, |
| 549 |
default=defaults.max_datagram_size, |
| 550 |
help="maximum datagram size to send, excluding UDP or IP overhead", |
| 551 |
) |
| 552 |
parser.add_argument( |
| 553 |
"--zero-rtt", action="store_true", help="try to send requests using 0-RTT" |
| 554 |
) |
| 555 |
|
| 556 |
args = parser.parse_args() |
| 557 |
|
| 558 |
logging.basicConfig( |
| 559 |
format="%(asctime)s %(levelname)s %(name)s %(message)s", |
| 560 |
level=logging.DEBUG if args.verbose else logging.INFO, |
| 561 |
) |
| 562 |
|
| 563 |
if args.output_dir is not None and not os.path.isdir(args.output_dir): |
| 564 |
raise Exception("%s is not a directory" % args.output_dir) |
| 565 |
|
| 566 |
|
| 567 |
configuration = QuicConfiguration( |
| 568 |
is_client=True, |
| 569 |
alpn_protocols=H0_ALPN if args.legacy_http else H3_ALPN, |
| 570 |
congestion_control_algorithm=args.congestion_control_algorithm, |
| 571 |
max_datagram_size=args.max_datagram_size, |
| 572 |
) |
| 573 |
if args.ca_certs: |
| 574 |
configuration.load_verify_locations(args.ca_certs) |
| 575 |
if args.cipher_suites: |
| 576 |
configuration.cipher_suites = [ |
| 577 |
CipherSuite[s] for s in args.cipher_suites.split(",") |
| 578 |
] |
| 579 |
if args.insecure: |
| 580 |
configuration.verify_mode = ssl.CERT_NONE |
| 581 |
if args.max_data: |
| 582 |
configuration.max_data = args.max_data |
| 583 |
if args.max_stream_data: |
| 584 |
configuration.max_stream_data = args.max_stream_data |
| 585 |
if args.negotiate_v2: |
| 586 |
configuration.original_version = QuicProtocolVersion.VERSION_1 |
| 587 |
configuration.supported_versions = [ |
| 588 |
QuicProtocolVersion.VERSION_2, |
| 589 |
QuicProtocolVersion.VERSION_1, |
| 590 |
] |
| 591 |
if args.quic_log: |
| 592 |
configuration.quic_logger = QuicFileLogger(args.quic_log) |
| 593 |
if args.secrets_log: |
| 594 |
configuration.secrets_log_file = open(args.secrets_log, "a") |
| 595 |
if args.session_ticket: |
| 596 |
try: |
| 597 |
with open(args.session_ticket, "rb") as fp: |
| 598 |
configuration.session_ticket = pickle.load(fp) |
| 599 |
except FileNotFoundError: |
| 600 |
pass |
| 601 |
|
| 602 |
|
| 603 |
if args.certificate is not None: |
| 604 |
configuration.load_cert_chain(args.certificate, args.private_key) |
| 605 |
|
| 606 |
if uvloop is not None: |
| 607 |
uvloop.install() |
| 608 |
asyncio.run( |
| 609 |
main( |
| 610 |
configuration=configuration, |
| 611 |
urls=args.url, |
| 612 |
data=args.data, |
| 613 |
include=args.include, |
| 614 |
output_dir=args.output_dir, |
| 615 |
local_port=args.local_port, |
| 616 |
key_update=args.key_update, |
| 617 |
zero_rtt=args.zero_rtt, |
| 618 |
) |
| 619 |
) |