From 34ca0f097c0607c1dd6610e3fad6eebaa11fe11c Mon Sep 17 00:00:00 2001 From: Michael Barton Date: Fri, 9 Nov 2012 10:11:08 -0800 Subject: [PATCH] give swob default content-type This should fix up the few remaining API regressions from swob, by giving all responses a default content-type of "text/html; charset=UTF-8". Change-Id: Ib3b859e63c5e8c4af6f7fe535947402b5df57399 --- swift/common/swob.py | 4 ++-- swift/proxy/controllers/base.py | 1 - test/functionalnosetests/test_container.py | 15 +++++++++++++++ test/functionalnosetests/test_object.py | 22 ++++++++++++++++++++++ 4 files changed, 39 insertions(+), 3 deletions(-) diff --git a/swift/common/swob.py b/swift/common/swob.py index ae192fc7e6..baca9313c9 100755 --- a/swift/common/swob.py +++ b/swift/common/swob.py @@ -847,7 +847,8 @@ class Response(object): def __init__(self, body=None, status=200, headers={}, app_iter=None, request=None, conditional_response=False, **kw): - self.headers = HeaderKeyDict() + self.headers = HeaderKeyDict( + [('Content-Type', 'text/html; charset=UTF-8')]) self.conditional_response = conditional_response self.request = request self.body = body @@ -948,7 +949,6 @@ class Response(object): return [body] if self.status_int in RESPONSE_REASONS: title, exp = RESPONSE_REASONS[self.status_int] - self.content_type = 'text/html; charset=UTF-8' if exp: body = '

%s

%s

' % (title, exp) self.content_length = len(body) diff --git a/swift/proxy/controllers/base.py b/swift/proxy/controllers/base.py index c49733afa9..d406540dc7 100644 --- a/swift/proxy/controllers/base.py +++ b/swift/proxy/controllers/base.py @@ -481,7 +481,6 @@ class Controller(object): status_index = statuses.index(status) resp.status = '%s %s' % (status, reasons[status_index]) resp.body = bodies[status_index] - resp.content_type = 'text/html' if etag: resp.headers['etag'] = etag.strip('"') return resp diff --git a/test/functionalnosetests/test_container.py b/test/functionalnosetests/test_container.py index 738231e02b..f621f58dc0 100755 --- a/test/functionalnosetests/test_container.py +++ b/test/functionalnosetests/test_container.py @@ -522,6 +522,21 @@ class TestContainer(unittest.TestCase): resp.read() self.assertEquals(resp.status, 201) + def test_long_name_content_type(self): + if skip: + raise SkipTest + + def put(url, token, parsed, conn): + container_name = 'X' * 2048 + conn.request('PUT', '%s/%s' % (parsed.path, + container_name), 'there', {'X-Auth-Token': token}) + return check_response(conn) + resp = retry(put) + resp.read() + self.assertEquals(resp.status, 400) + self.assertEquals(resp.getheader('Content-Type'), + 'text/html; charset=UTF-8') + if __name__ == '__main__': unittest.main() diff --git a/test/functionalnosetests/test_object.py b/test/functionalnosetests/test_object.py index 5975cf16a2..cb5411df0f 100644 --- a/test/functionalnosetests/test_object.py +++ b/test/functionalnosetests/test_object.py @@ -541,6 +541,28 @@ class TestObject(unittest.TestCase): resp.read() self.assertEquals(resp.status, 204) + def test_delete_content_type(self): + if skip: + raise SkipTest + + def put(url, token, parsed, conn): + conn.request('PUT', '%s/%s/hi' % (parsed.path, + self.container), 'there', {'X-Auth-Token': token}) + return check_response(conn) + resp = retry(put) + resp.read() + self.assertEquals(resp.status, 201) + + def delete(url, token, parsed, conn): + conn.request('DELETE', '%s/%s/hi' % (parsed.path, self.container), + '', {'X-Auth-Token': token}) + return check_response(conn) + resp = retry(delete) + resp.read() + self.assertEquals(resp.status, 204) + self.assertEquals(resp.getheader('Content-Type'), + 'text/html; charset=UTF-8') + if __name__ == '__main__': unittest.main()

AltStyle によって変換されたページ (->オリジナル) /