From c3ca82e7e59d3acccd1a7d8d89d8b6210019d622 Mon Sep 17 00:00:00 2001 From: Ivan Mahonin Date: Aug 10 2025 10:09:46 +0000 Subject: allow http+unix proxy --- diff --git a/deps.txt b/deps.txt index 412c325..044d12c 100644 --- a/deps.txt +++ b/deps.txt @@ -20,6 +20,7 @@ base64 cgi html http.client +socket shutil urllib.parse uuid diff --git a/repoproxy.py b/repoproxy.py index 765598b..926d9d8 100644 --- a/repoproxy.py +++ b/repoproxy.py @@ -1,6 +1,7 @@ import base64 +import socket import http.client import urllib.parse @@ -74,15 +75,27 @@ class RepoProxy: print('repoproxy: authorization in url is not supported [' + auth + '][' + fullurl + ']') return self.badgateway() + sock = None connection_class = None if protocol == 'https': connection_class = http.client.HTTPSConnection elif protocol == 'http': connection_class = http.client.HTTPConnection + elif protocol == 'http+unix': + connection_class = http.client.HTTPConnection + sockfile = urllib.parse.unquote(host) + host = 'localhost' + try: + sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) + sock.connect(sockfile) + except Exception as e: + print('repoproxy: cannot connect to unix socket [' + sockfile + ']') + print(e) + return self.badgateway() if not connection_class: print('repoproxy: protocol is not supported [' + protocol + '][' + fullurl + ']') return self.badgateway() - + body = self.input_reader(request) header_prefix = 'HTTP_' @@ -100,10 +113,11 @@ class RepoProxy: except Exception: pass proxy_headers['host'] = host - + connection = None try: connection = connection_class(host = host, port = port) + if sock: connection.sock = sock connection.request( request.method, url,