From fe495ce21a2acadf7b3949288bb887fe8f3468c3 Mon Sep 17 00:00:00 2001 From: mervent Date: Wed, 16 Mar 2022 21:04:28 +0300 Subject: [PATCH] Obey RFC2616 https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html An HTTP/1.1 proxy MUST ensure that any request message it forwards does contain an appropriate Host header field that identifies the service being requested by the proxy. All Internet-based HTTP/1.1 servers MUST respond with a 400 (Bad Request) status code to any HTTP/1.1 request message which lacks a Host header field. --- pproxy/proto.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pproxy/proto.py b/pproxy/proto.py index eb40287..1572fb4 100644 --- a/pproxy/proto.py +++ b/pproxy/proto.py @@ -328,8 +328,8 @@ async def connected(writer): writer.write(f'{method} {newpath} {ver}\r\n{lines}\r\n\r\n'.encode()) return True return user, host_name, port, connected - async def connect(self, reader_remote, writer_remote, rauth, host_name, port, myhost, **kw): - writer_remote.write(f'CONNECT {host_name}:{port} HTTP/1.1\r\nHost: {myhost}'.encode() + (b'\r\nProxy-Authorization: Basic '+base64.b64encode(rauth) if rauth else b'') + b'\r\n\r\n') + async def connect(self, reader_remote, writer_remote, rauth, host_name, port, **kw): + writer_remote.write(f'CONNECT {host_name}:{port} HTTP/1.1\r\nHost: {host_name}:{port}'.encode() + (b'\r\nProxy-Authorization: Basic '+base64.b64encode(rauth) if rauth else b'') + b'\r\n\r\n') await reader_remote.read_until(b'\r\n\r\n') async def http_channel(self, reader, writer, stat_bytes, stat_conn): try: