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
This commit is contained in:
parent
2194897e37
commit
34ca0f097c
@ -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 = '<html><h1>%s</h1><p>%s</p></html>' % (title, exp)
|
||||
self.content_length = len(body)
|
||||
|
@ -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
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user