summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcel Hellkamp <marc@gsites.de>2013-01-21 13:18:58 +0100
committerMarcel Hellkamp <marc@gsites.de>2013-01-21 13:26:08 +0100
commit0f193b092e1cf328e9b948455a342d9811150cd0 (patch)
tree381347575547f4787bba0c2a3934ddc6f3d93bf0
parenta96d69d3cf851245117b9118a534c08dbae9b06b (diff)
downloadbottle-0f193b092e1cf328e9b948455a342d9811150cd0.tar.gz
fix #438: "Some cookies are lost when using mount()"
Added support for multiple headers with the same name (e.g. Set-Cookie) for mounted apps.
-rw-r--r--bottle.py10
-rw-r--r--test/test_mount.py11
2 files changed, 14 insertions, 7 deletions
diff --git a/bottle.py b/bottle.py
index baa935d..44c29f5 100644
--- a/bottle.py
+++ b/bottle.py
@@ -561,14 +561,14 @@ class Bottle(object):
def mountpoint_wrapper():
try:
request.path_shift(path_depth)
- rs = BaseResponse([], 200)
- def start_response(status, header):
+ rs = HTTPResponse([])
+ def start_response(status, headerlist):
rs.status = status
- for name, value in header: rs.add_header(name, value)
+ for name, value in headerlist: rs.add_header(name, value)
return rs.body.append
body = app(request.environ, start_response)
- body = itertools.chain(rs.body, body)
- return HTTPResponse(body, rs.status_code, **rs.headers)
+ if body: rs.body = itertools.chain(rs.body, body)
+ return rs
finally:
request.path_shift(-path_depth)
diff --git a/test/test_mount.py b/test/test_mount.py
index b67d5d8..ef1457a 100644
--- a/test/test_mount.py
+++ b/test/test_mount.py
@@ -1,6 +1,6 @@
import bottle
from tools import ServerTestBase
-from bottle import Bottle
+from bottle import Bottle, response
class TestAppMounting(ServerTestBase):
def setUp(self):
@@ -61,7 +61,14 @@ class TestAppMounting(ServerTestBase):
self.assertBody('WSGI /', '/test/')
self.assertHeader('X-Test', 'WSGI', '/test/')
self.assertBody('WSGI /test/bar', '/test/test/bar')
-
+
+ def test_mount_wsgi(self):
+ @self.subapp.route('/cookie')
+ def test_cookie():
+ response.set_cookie('a', 'a')
+ response.set_cookie('b', 'b')
+ self.app.mount('/test', self.subapp)
+ self.assertHeader('Set-Cookie', 'a=a, b=b', '/test/cookie')
class TestAppMerging(ServerTestBase):
def setUp(self):