wsgi: UNIX socket address was trimmed in "wsgi starting" log; Thanks to Ihar Hrachyshka
For UNIX sockets, getsockname() returns a string, not a 2-tuple, that represents the file path that is assigned to it. That's why we need a special handling for the socket type. https://github.com/eventlet/eventlet/issues/235
This commit is contained in:
1
AUTHORS
1
AUTHORS
@@ -120,3 +120,4 @@ Thanks To
|
||||
* Tim Simmons, Use _socket_nodns and select in dnspython support
|
||||
* Antonio Cuni, fix fd double close on PyPy
|
||||
* Seyeong Kim
|
||||
* Ihar Hrachyshka
|
||||
|
@@ -711,6 +711,24 @@ except ImportError:
|
||||
ACCEPT_ERRNO = set((errno.EPIPE, errno.EBADF, errno.ECONNRESET))
|
||||
|
||||
|
||||
def socket_repr(sock):
|
||||
scheme = 'http'
|
||||
if hasattr(sock, 'do_handshake'):
|
||||
scheme = 'https'
|
||||
|
||||
name = sock.getsockname()
|
||||
if sock.family == socket.AF_INET:
|
||||
hier_part = '//{0}:{1}'.format(*name)
|
||||
elif sock.family == socket.AF_INET6:
|
||||
hier_part = '//[{0}]:{1}'.format(*name[:2])
|
||||
elif sock.family == socket.AF_UNIX:
|
||||
hier_part = name
|
||||
else:
|
||||
hier_part = repr(name)
|
||||
|
||||
return scheme + ':' + hier_part
|
||||
|
||||
|
||||
def server(sock, site,
|
||||
log=None,
|
||||
environ=None,
|
||||
@@ -805,19 +823,8 @@ def server(sock, site,
|
||||
else:
|
||||
pool = greenpool.GreenPool(max_size)
|
||||
try:
|
||||
host, port = sock.getsockname()[:2]
|
||||
port = ':%s' % (port, )
|
||||
if hasattr(sock, 'do_handshake'):
|
||||
scheme = 'https'
|
||||
if port == ':443':
|
||||
port = ''
|
||||
else:
|
||||
scheme = 'http'
|
||||
if port == ':80':
|
||||
port = ''
|
||||
|
||||
serv.log.info("(%s) wsgi starting up on %s://%s%s/" % (
|
||||
serv.pid, scheme, host, port))
|
||||
serv.log.info("(%s) wsgi starting up on %s" % (
|
||||
serv.pid, socket_repr(sock)))
|
||||
while is_accepting:
|
||||
try:
|
||||
client_socket = sock.accept()
|
||||
|
@@ -2,9 +2,11 @@ import cgi
|
||||
import collections
|
||||
import errno
|
||||
import os
|
||||
import shutil
|
||||
import signal
|
||||
import socket
|
||||
import sys
|
||||
import tempfile
|
||||
import traceback
|
||||
import unittest
|
||||
|
||||
@@ -1488,6 +1490,20 @@ class TestHttpd(_TestBase):
|
||||
self.assertEqual(result.headers_lower[random_case_header[0].lower()], random_case_header[1])
|
||||
self.assertEqual(result.headers_original[random_case_header[0]], random_case_header[1])
|
||||
|
||||
def test_log_unix_address(self):
|
||||
tempdir = tempfile.mkdtemp('eventlet_test_log_unix_address')
|
||||
path = ''
|
||||
try:
|
||||
sock = eventlet.listen(tempdir + '/socket', socket.AF_UNIX)
|
||||
path = sock.getsockname()
|
||||
|
||||
log = six.StringIO()
|
||||
self.spawn_server(sock=sock, log=log)
|
||||
eventlet.sleep(0) # need to enter server loop
|
||||
assert 'http:' + path in log.getvalue()
|
||||
finally:
|
||||
shutil.rmtree(tempdir)
|
||||
|
||||
|
||||
def read_headers(sock):
|
||||
fd = sock.makefile('rb')
|
||||
|
Reference in New Issue
Block a user