diff options
author | Marcel Hellkamp <marc@gsites.de> | 2015-04-01 20:42:37 +0200 |
---|---|---|
committer | Marcel Hellkamp <marc@gsites.de> | 2015-11-01 00:02:15 +0100 |
commit | cec4f3fa9ed86817c3e67ee67ad0166ef0c76ea0 (patch) | |
tree | c9f7b054304473630880de68c248865736d65d0d | |
parent | 87fe32987cd11414adb23fa32552f3310cccee0a (diff) | |
download | bottle-cec4f3fa9ed86817c3e67ee67ad0166ef0c76ea0.tar.gz |
Fix #671: Fix based on PR #717
-rw-r--r-- | bottle.py | 14 | ||||
-rwxr-xr-x | test/test_wsgi.py | 12 |
2 files changed, 25 insertions, 1 deletions
@@ -948,7 +948,19 @@ class Bottle(object): request.bind(environ) response.bind() self.trigger_hook('before_request') - out = self._inner_handle(environ) + + try: + route, args = self.router.match(environ) + environ['route.handle'] = route + environ['bottle.route'] = route + environ['route.url_args'] = args + out = route.call(**args) + except HTTPResponse: + out = _e() + except RouteReset: + route.reset() + return self._handle(environ) + return out except (KeyboardInterrupt, SystemExit, MemoryError): exc = _e() diff --git a/test/test_wsgi.py b/test/test_wsgi.py index 74ed37f..121b828 100755 --- a/test/test_wsgi.py +++ b/test/test_wsgi.py @@ -255,6 +255,18 @@ class TestRouteDecorator(ServerTestBase): self.assertBody('before', '/test') self.assertHeader('X-Hook', 'after', '/test') + def test_environ_reflects_correct_response_after_request_in_hooks(self): + """ Issue #671 """ + + @bottle.hook('after_request') + def log_request_a(): + self.assertStatus(400) + self.assertBody("test") + + @bottle.get('/') + def _get(): + bottle.abort(400, 'test') + def test_template(self): @bottle.route(template='test {{a}} {{b}}') def test(): return dict(a=5, b=6) |