From dcca21af3d9c12834455c8e4c7c57828f1b6ea08 Mon Sep 17 00:00:00 2001 From: alexia Date: Mon, 27 Mar 2023 14:31:07 +0200 Subject: [PATCH 1/2] feat(proto.httponly): fall back to CONNECT for port 443 --- pproxy/proto.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pproxy/proto.py b/pproxy/proto.py index eb40287..2347cee 100644 --- a/pproxy/proto.py +++ b/pproxy/proto.py @@ -359,6 +359,8 @@ async def http_channel(self, reader, writer, stat_bytes, stat_conn): class HTTPOnly(HTTP): async def connect(self, reader_remote, writer_remote, rauth, host_name, port, myhost, **kw): + if port == 443: # TODO: Is there a better way to detect HTTPS protocol? + return await super().connect(reader_remote, writer_remote, rauth, host_name, port, myhost, **kw) buffer = bytearray() HOST_NAME = re.compile('\r\nHost: ([^\r\n]+)\r\n', re.I) def write(data, o=writer_remote.write): From 98333c7c761afdda1461700eb0002190877b832a Mon Sep 17 00:00:00 2001 From: Jonney Date: Mon, 27 Mar 2023 19:58:03 +0800 Subject: [PATCH 2/2] Compatible with Python 3.11 In Python 3.11, asyncio.sslproto.SSLProtocol inherits from asyncio.protocols.BufferedProtocol. In SSLProtocol, data_received() is no longer used and has been replaced with get_buffer() and buffer_updated(). --- pproxy/proto.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/pproxy/proto.py b/pproxy/proto.py index 2347cee..1f32a5a 100644 --- a/pproxy/proto.py +++ b/pproxy/proto.py @@ -618,12 +618,21 @@ def abort(self): self.close() ssl.connection_made(Transport()) async def channel(): + read_size=65536 + buffer=None + if hasattr(ssl,'get_buffer'): + buffer=ssl.get_buffer(read_size) try: while not reader.at_eof() and not ssl._app_transport._closed: - data = await reader.read(65536) + data = await reader.read(read_size) if not data: break - ssl.data_received(data) + if buffer!=None: + data_len=len(data) + buffer[:data_len]=data + ssl.buffer_updated(data_len) + else: + ssl.data_received(data) except Exception: pass finally: