summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcel Hellkamp <marc@gsites.de>2015-04-01 20:42:37 +0200
committerMarcel Hellkamp <marc@gsites.de>2015-11-01 00:02:15 +0100
commitcec4f3fa9ed86817c3e67ee67ad0166ef0c76ea0 (patch)
treec9f7b054304473630880de68c248865736d65d0d
parent87fe32987cd11414adb23fa32552f3310cccee0a (diff)
downloadbottle-cec4f3fa9ed86817c3e67ee67ad0166ef0c76ea0.tar.gz
Fix #671: Fix based on PR #717
-rw-r--r--bottle.py14
-rwxr-xr-xtest/test_wsgi.py12
2 files changed, 25 insertions, 1 deletions
diff --git a/bottle.py b/bottle.py
index ed743d4..28b8f1a 100644
--- a/bottle.py
+++ b/bottle.py
@@ -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)