Merge "Don't allow webob to set a default content type"

This commit is contained in:
Jenkins 2015-07-06 23:40:35 +00:00 committed by Gerrit Code Review
commit 4e7c4ed250
2 changed files with 32 additions and 0 deletions

View File

@ -53,8 +53,17 @@ def _v3_to_v2_catalog(catalog):
return v2_services
# NOTE(jamielennox): this should probably be moved into its own file, but at
# the moment there's no real logic here so just keep it locally.
class _AuthTokenResponse(webob.Response):
default_content_type = None # prevents webob assigning a content type
class _AuthTokenRequest(webob.Request):
ResponseClass = _AuthTokenResponse
_HEADER_TEMPLATE = {
'X%s-Domain-Id': 'domain_id',
'X%s-Domain-Name': 'domain_name',

View File

@ -1326,6 +1326,29 @@ class CommonAuthTokenMiddlewareTest(object):
self.assertFalse(token_auth.has_service_token)
self.assertIsNone(token_auth.service)
def test_doesnt_auto_set_content_type(self):
# webob will set content_type = 'text/html' by default if nothing is
# provided. We don't want our middleware messing with the content type
# of the underlying applications.
text = uuid.uuid4().hex
def _middleware(environ, start_response):
start_response(200, [])
return text
def _start_response(status_code, headerlist, exc_info=None):
self.assertIn('200', status_code) # will be '200 OK'
self.assertEqual([], headerlist)
m = auth_token.AuthProtocol(_middleware, self.conf)
env = {'REQUEST_METHOD': 'GET',
'HTTP_X_AUTH_TOKEN': self.token_dict['uuid_token_default']}
r = m(env, _start_response)
self.assertEqual(text, r)
class V2CertDownloadMiddlewareTest(BaseAuthTokenMiddlewareTest,
testresources.ResourcedTestCase):