diff --git a/tornado/httpserver.py b/tornado/httpserver.py index 5df8da3e..e930e9f7 100644 --- a/tornado/httpserver.py +++ b/tornado/httpserver.py @@ -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: