From 983dd706550ea99a9db08e6a037374bda19aa2a5 Mon Sep 17 00:00:00 2001 From: Marcel Hellkamp Date: Sun, 8 Dec 2019 20:28:13 +0100 Subject: Added tests for #1125 fix. --- test/test_wsgi.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/test/test_wsgi.py b/test/test_wsgi.py index 72563fc..e999a88 100755 --- a/test/test_wsgi.py +++ b/test/test_wsgi.py @@ -2,7 +2,7 @@ import unittest import bottle from tools import ServerTestBase -from bottle import tob +from bottle import tob, HTTPResponse class TestWsgi(ServerTestBase): ''' Tests for WSGI functionality, routing and output casting (decorators) ''' @@ -243,6 +243,27 @@ class TestRouteDecorator(ServerTestBase): self.assertBody('before', '/test') self.assertHeader('X-Hook', 'after', '/test') + def test_after_response_hook_can_set_headers(self): + """ Issue #1125 """ + + @bottle.route() + def test1(): + return "test" + @bottle.route() + def test2(): + return HTTPResponse("test", 200) + @bottle.route() + def test3(): + raise HTTPResponse("test", 200) + + @bottle.hook('after_request') + def hook(): + bottle.response.headers["X-Hook"] = 'works' + + for route in ("/test1", "/test2", "/test3"): + self.assertBody('test', route) + self.assertHeader('X-Hook', 'works', route) + def test_template(self): @bottle.route(template='test {{a}} {{b}}') def test(): return dict(a=5, b=6) -- cgit v1.2.1