Permalink
Browse files

Delay check for socket.family (and make it jython-friendly).

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.
  • Loading branch information...
bdarnell committed May 26, 2012
1 parent 7d4623b commit e5d5d3241f81fa7ad5052079ba9cf6b2daf7c25b
Showing with 12 additions and 4 deletions.
  1. +12 −4 tornado/httpserver.py
View
@@ -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 @@ def _on_headers(self, data):
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:

0 comments on commit e5d5d32

Please sign in to comment.