diff options
author | Marcel Hellkamp <marc@gsites.de> | 2013-02-01 20:12:49 +0100 |
---|---|---|
committer | Marcel Hellkamp <marc@gsites.de> | 2013-02-01 20:20:16 +0100 |
commit | d0617f5ac0cc9519460052078bb5277412596647 (patch) | |
tree | 936f0fe33d51d117b10f299a3e2a811583b189bc | |
parent | 3cc41c83545d43d3577bf88cd160dd64ab146359 (diff) | |
download | bottle-d0617f5ac0cc9519460052078bb5277412596647.tar.gz |
Fix #446 (also #438): Wrong subapp response body handling and lost Content-Type header on mounted apps.
-rw-r--r-- | bottle.py | 9 | ||||
-rw-r--r-- | test/test_mount.py | 15 |
2 files changed, 21 insertions, 3 deletions
@@ -567,7 +567,8 @@ class Bottle(object): for name, value in headerlist: rs.add_header(name, value) return rs.body.append body = app(request.environ, start_response) - if body: rs.body = itertools.chain(rs.body, body) + if body and rs.body: body = itertools.chain(rs.body, body) + rs.body = body or rs.body return rs finally: request.path_shift(-path_depth) @@ -1285,7 +1286,7 @@ class BaseResponse(object): def __init__(self, body='', status=None, **headers): self._cookies = None - self._headers = {'Content-Type': [self.default_content_type]} + self._headers = {} self.body = body self.status = status or self.default_status if headers: @@ -1379,7 +1380,9 @@ class BaseResponse(object): def headerlist(self): ''' WSGI conform list of (header, value) tuples. ''' out = [] - headers = self._headers.items() + headers = list(self._headers.items()) + if 'Content-Type' not in self._headers: + headers.append(('Content-Type', [self.default_content_type])) if self._status_code in self.bad_headers: bad_headers = self.bad_headers[self._status_code] headers = [h for h in headers if h[0] not in bad_headers] diff --git a/test/test_mount.py b/test/test_mount.py index 0d951e0..11d8ef6 100644 --- a/test/test_mount.py +++ b/test/test_mount.py @@ -71,6 +71,21 @@ class TestAppMounting(ServerTestBase): c = self.urlopen('/test/cookie')['header']['Set-Cookie'] self.assertEqual(['a=a', 'b=b'], list(sorted(c.split(', ')))) + def test_mount_wsgi_ctype_bug(self): + status = {} + def app(environ, start_response): + start_response('200 OK', [('Content-Type', 'test/test')]) + return 'WSGI ' + environ['PATH_INFO'] + self.app.mount('/test', app) + self.assertHeader('Content-Type', 'test/test', '/test/') + + def test_mount_json_bug(self): + @self.subapp.route('/json') + def test_cookie(): + return {'a':5} + self.app.mount('/test', self.subapp) + self.assertHeader('Content-Type', 'application/json', '/test/json') + class TestAppMerging(ServerTestBase): def setUp(self): ServerTestBase.setUp(self) |