Merge "Disable case-changing behavior in Eventlet"

This commit is contained in:
Jenkins 2014-07-17 01:02:31 +00:00 committed by Gerrit Code Review
commit dbc2102652
3 changed files with 59 additions and 12 deletions

View File

@ -253,10 +253,10 @@ class ProxyLoggingMiddleware(object):
break break
else: else:
if not chunk: if not chunk:
start_response_args[0][1].append(('content-length', '0')) start_response_args[0][1].append(('Content-Length', '0'))
elif isinstance(iterable, list): elif isinstance(iterable, list):
start_response_args[0][1].append( start_response_args[0][1].append(
('content-length', str(sum(len(i) for i in iterable)))) ('Content-Length', str(sum(len(i) for i in iterable))))
start_response(*start_response_args[0]) start_response(*start_response_args[0])
req = Request(env) req = Request(env)

View File

@ -16,6 +16,7 @@
"""WSGI tools for use with swift.""" """WSGI tools for use with swift."""
import errno import errno
import inspect
import os import os
import signal import signal
import time import time
@ -386,7 +387,14 @@ def run_server(conf, logger, sock, global_conf=None):
max_clients = int(conf.get('max_clients', '1024')) max_clients = int(conf.get('max_clients', '1024'))
pool = RestrictedGreenPool(size=max_clients) pool = RestrictedGreenPool(size=max_clients)
try: try:
wsgi.server(sock, app, NullLogger(), custom_pool=pool) # Disable capitalizing headers in Eventlet if possible. This is
# necessary for the AWS SDK to work with swift3 middleware.
argspec = inspect.getargspec(wsgi.server)
if 'capitalize_response_headers' in argspec.args:
wsgi.server(sock, app, NullLogger(), custom_pool=pool,
capitalize_response_headers=False)
else:
wsgi.server(sock, app, NullLogger(), custom_pool=pool)
except socket.error as err: except socket.error as err:
if err[0] != errno.EINVAL: if err[0] != errno.EINVAL:
raise raise

View File

@ -333,10 +333,11 @@ class TestWSGI(unittest.TestCase):
'modify_wsgi_pipeline'): 'modify_wsgi_pipeline'):
with mock.patch('swift.common.wsgi.wsgi') as _wsgi: with mock.patch('swift.common.wsgi.wsgi') as _wsgi:
with mock.patch('swift.common.wsgi.eventlet') as _eventlet: with mock.patch('swift.common.wsgi.eventlet') as _eventlet:
conf = wsgi.appconfig(conf_file) with mock.patch('swift.common.wsgi.inspect'):
logger = logging.getLogger('test') conf = wsgi.appconfig(conf_file)
sock = listen(('localhost', 0)) logger = logging.getLogger('test')
wsgi.run_server(conf, logger, sock) sock = listen(('localhost', 0))
wsgi.run_server(conf, logger, sock)
self.assertEquals('HTTP/1.0', self.assertEquals('HTTP/1.0',
_wsgi.HttpProtocol.default_request_version) _wsgi.HttpProtocol.default_request_version)
self.assertEquals(30, _wsgi.WRITE_TIMEOUT) self.assertEquals(30, _wsgi.WRITE_TIMEOUT)
@ -354,6 +355,43 @@ class TestWSGI(unittest.TestCase):
self.assert_('custom_pool' in kwargs) self.assert_('custom_pool' in kwargs)
self.assertEquals(1000, kwargs['custom_pool'].size) self.assertEquals(1000, kwargs['custom_pool'].size)
def test_run_server_with_latest_eventlet(self):
config = """
[DEFAULT]
swift_dir = TEMPDIR
[pipeline:main]
pipeline = proxy-server
[app:proxy-server]
use = egg:swift#proxy
"""
def argspec_stub(server):
return mock.MagicMock(args=['capitalize_response_headers'])
contents = dedent(config)
with temptree(['proxy-server.conf']) as t:
conf_file = os.path.join(t, 'proxy-server.conf')
with open(conf_file, 'w') as f:
f.write(contents.replace('TEMPDIR', t))
_fake_rings(t)
with nested(
mock.patch('swift.proxy.server.Application.'
'modify_wsgi_pipeline'),
mock.patch('swift.common.wsgi.wsgi'),
mock.patch('swift.common.wsgi.eventlet'),
mock.patch('swift.common.wsgi.inspect',
getargspec=argspec_stub)) as (_, _wsgi, _, _):
conf = wsgi.appconfig(conf_file)
logger = logging.getLogger('test')
sock = listen(('localhost', 0))
wsgi.run_server(conf, logger, sock)
_wsgi.server.assert_called()
args, kwargs = _wsgi.server.call_args
self.assertEquals(kwargs.get('capitalize_response_headers'), False)
def test_run_server_conf_dir(self): def test_run_server_conf_dir(self):
config_dir = { config_dir = {
'proxy-server.conf.d/pipeline.conf': """ 'proxy-server.conf.d/pipeline.conf': """
@ -382,11 +420,12 @@ class TestWSGI(unittest.TestCase):
with mock.patch('swift.common.wsgi.wsgi') as _wsgi: with mock.patch('swift.common.wsgi.wsgi') as _wsgi:
with mock.patch('swift.common.wsgi.eventlet') as _eventlet: with mock.patch('swift.common.wsgi.eventlet') as _eventlet:
with mock.patch.dict('os.environ', {'TZ': ''}): with mock.patch.dict('os.environ', {'TZ': ''}):
conf = wsgi.appconfig(conf_dir) with mock.patch('swift.common.wsgi.inspect'):
logger = logging.getLogger('test') conf = wsgi.appconfig(conf_dir)
sock = listen(('localhost', 0)) logger = logging.getLogger('test')
wsgi.run_server(conf, logger, sock) sock = listen(('localhost', 0))
self.assert_(os.environ['TZ'] is not '') wsgi.run_server(conf, logger, sock)
self.assert_(os.environ['TZ'] is not '')
self.assertEquals('HTTP/1.0', self.assertEquals('HTTP/1.0',
_wsgi.HttpProtocol.default_request_version) _wsgi.HttpProtocol.default_request_version)