]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Delay check for socket.family (and make it jython-friendly).
authorBen Darnell <ben@bendarnell.com>
Sat, 26 May 2012 18:35:42 +0000 (11:35 -0700)
committerBen Darnell <ben@bendarnell.com>
Sat, 26 May 2012 18:35:42 +0000 (11:35 -0700)
Now HTTPConnection.address will always be the socket address,
and the fake "0.0.0.0" IP is only used in contexts that want an IP
(i.e. HTTPRequest.remote_ip) but the connection is a non-IP socket.

tornado/httpserver.py

index 5df8da3ecb7e4d5b6a68f61eaed4d0456a7cefd7..e930e9f707adfcd540b8898b6d22c8e699189f33 100644 (file)
@@ -161,9 +161,6 @@ class HTTPConnection(object):
     def __init__(self, stream, address, request_callback, no_keep_alive=False,
                  xheaders=False):
         self.stream = stream
-        if self.stream.socket.family not in (socket.AF_INET, socket.AF_INET6):
-            # Unix (or other) socket; fake the remote address
-            address = ('0.0.0.0', 0)
         self.address = address
         self.request_callback = request_callback
         self.no_keep_alive = no_keep_alive
@@ -238,9 +235,20 @@ class HTTPConnection(object):
             if not version.startswith("HTTP/"):
                 raise _BadRequestException("Malformed HTTP version in HTTP Request-Line")
             headers = httputil.HTTPHeaders.parse(data[eol:])
+
+            # HTTPRequest wants an IP, not a full socket address
+            if getattr(self.stream.socket, 'family', socket.AF_INET) in (
+                socket.AF_INET, socket.AF_INET6):
+                # Jython 2.5.2 doesn't have the socket.family attribute,
+                # so just assume IP in that case.
+                remote_ip = self.address[0]
+            else:
+                # Unix (or other) socket; fake the remote address
+                remote_ip = '0.0.0.0'
+
             self._request = HTTPRequest(
                 connection=self, method=method, uri=uri, version=version,
-                headers=headers, remote_ip=self.address[0])
+                headers=headers, remote_ip=remote_ip)
 
             content_length = headers.get("Content-Length")
             if content_length: