diff --git a/proxyplugin.py b/proxyplugin.py index 4a1ab1b..4da0b6f 100644 --- a/proxyplugin.py +++ b/proxyplugin.py @@ -1,6 +1,7 @@ from __future__ import unicode_literals, absolute_import +import socket import base64 import urllib.parse import os @@ -224,9 +225,11 @@ def reader(data, connection = None): def httpproxy(host, port, login): + sockfile = None + if not port: sockfile=host; host='localhost'; port=80 assert(host) assert(port) - + skip_headers = { 'connection', 'keep-alive', @@ -277,12 +280,16 @@ def httpproxy(host, port, login): connection = None try: connection = HTTPConnection(host = host, port = port) + if sockfile: + connection.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) + connection.sock.connect(sockfile) connection.request( method, uri, body = body, headers = proxy_headers ) except Exception as e: + print(e) return badgateway() response = connection.getresponse() @@ -290,6 +297,8 @@ def httpproxy(host, port, login): for k, v in response.getheaders(): if not k.lower() in skip_headers: headers.append( (k, v) ) + print(response.status, response.reason) + #print(headers) return flask.Response( reader(response, connection),