Closed Newcool1230 closed 9 months ago
Connections are sometimes closed by the client, this is normal.
The forward_data
function should look something like this
async def forward_data(reader: StreamReader, writer: StreamWriter):
try:
while not reader.at_eof() and not writer.is_closing():
data = await reader.read(65536)
if not data:
break
writer.write(data)
await writer.drain()
except (asyncio.CancelledError, ConnectionResetError): # maybe some other exceptions
pass # log it?
finally:
writer.close()
Also you should not pass ssl
and server_hostname
arguments to asyncio.open_connection
, TLS communication must be performed directly between the client and the target server
Also you should not pass
ssl
andserver_hostname
arguments toasyncio.open_connection
, TLS communication must be performed directly between the client and the target server
Thank you for getting back to me so quickly. This was the answer! After removing ssl
and server_hostname
it works correctly!
target_reader, target_writer = await asyncio.open_connection(sock=sock)
I've also updated my forward_data
to better catch these errors! Thank you!
Hey there,
I'm having some trouble with async proxy connections. My goal is to create an asyncio HTTP proxy server. I'm getting a connection lost error after trying to forward the data.
I'm testing this through Firefox's
proxy.onRequest API
:manifest.json
If I run it normally without the proxy connection it will work just fine.
I was also able to get the proxy working in sync but once I moved to asyncio it will lose connection.