浏览代码

Allow unix domain sockets via "unix://" URLs.

Chris McDonough 19 年之前
父节点
当前提交
dcf3d9f052
共有 1 个文件被更改,包括 11 次插入6 次删除
  1. 11 6
      src/supervisor/http_client.py

+ 11 - 6
src/supervisor/http_client.py

@@ -56,7 +56,7 @@ class HTTPHandler(object, asynchat.async_chat):
         assert(self.url==None, "Already doing a get") #@@
         self.url = url
         scheme, host, path, params, query, fragment = urlparse(url)
-        if not scheme=="http":
+        if not scheme in ("http", "unix"):
             raise NotImplementedError
         self.host = host
         if ":" in host:
@@ -68,11 +68,16 @@ class HTTPHandler(object, asynchat.async_chat):
 
         self.path = "?".join([path, query])
         self.port = port
-        
-        ip = hostname
-        self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
-        self.connect((ip, self.port))
-            
+
+        if scheme == "http":
+            ip = hostname
+            self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
+            self.connect((ip, self.port))
+        elif scheme == "unix":
+            socketname, path = url[7:].split('/', 1)
+            self.path = '/' + path
+            self.create_socket(socket.AF_UNIX, socket.SOCK_STREAM)
+            self.connect(socketname)
     
     def close (self):
         self.listener.close(self.url)