Fix logic for recreating connections
This commit is contained in:
parent
5180aa1192
commit
26c0765bb0
|
@ -98,7 +98,7 @@ class HttpClient(QuicConnectionProtocol):
|
||||||
|
|
||||||
self._http.send_headers(
|
self._http.send_headers(
|
||||||
stream_id=stream_id,
|
stream_id=stream_id,
|
||||||
headers=[(k, v)for k, v in headers.items()],
|
headers=[(k, v) for k, v in headers.items()],
|
||||||
)
|
)
|
||||||
self._http.send_data(stream_id=stream_id, data=http_request.content, end_stream=True)
|
self._http.send_data(stream_id=stream_id, data=http_request.content, end_stream=True)
|
||||||
|
|
||||||
|
@ -186,21 +186,27 @@ class RequestProcessor:
|
||||||
async def request_worker(self):
|
async def request_worker(self):
|
||||||
configuration = QuicConfiguration(is_client=True, alpn_protocols=H3_ALPN)
|
configuration = QuicConfiguration(is_client=True, alpn_protocols=H3_ALPN)
|
||||||
|
|
||||||
while self.recreate_connection_check():
|
while await self.recreate_connection_check():
|
||||||
async with connect("youtube.com", 443, configuration=configuration, create_protocol=HttpClient) as client:
|
async with connect("youtube.com", 443, configuration=configuration, create_protocol=HttpClient) as client:
|
||||||
while client._quic._state is not ConnectionTerminated:
|
while True:
|
||||||
await self._handle_request(client)
|
status = await self._handle_request(client)
|
||||||
|
# Connection has been terminated.
|
||||||
|
if status is False:
|
||||||
|
break
|
||||||
|
|
||||||
async def _handle_request(self, client):
|
async def _handle_request(self, client):
|
||||||
request, storage = await self.requests_to_do.get()
|
request, storage = await self.requests_to_do.get()
|
||||||
|
|
||||||
|
if client._quic._state is ConnectionTerminated:
|
||||||
|
return False
|
||||||
|
|
||||||
await perform_http_request(client=client, url=request.url, method=request.method,
|
await perform_http_request(client=client, url=request.url, method=request.method,
|
||||||
headers=request.headers, data=request.content,
|
headers=request.headers, data=request.content,
|
||||||
store_at=storage)
|
store_at=storage)
|
||||||
|
|
||||||
request.completed.set()
|
request.completed.set()
|
||||||
|
|
||||||
def recreate_connection_check(self):
|
async def recreate_connection_check(self):
|
||||||
# TODO in the future this code should calculate whether or not to recreate a connection based on the amount
|
# TODO in the future this code should calculate whether or not to recreate a connection based on the amount
|
||||||
# of connections currently available and the amount of traffic we're currently receiving. For now we'll
|
# of connections currently available and the amount of traffic we're currently receiving. For now we'll
|
||||||
# just have it recreate a connection anytime it's broken.
|
# just have it recreate a connection anytime it's broken.
|
||||||
|
|
Loading…
Reference in New Issue