diff options
author | Marcel Hellkamp <marc@gsites.de> | 2022-05-26 14:49:32 +0200 |
---|---|---|
committer | Marcel Hellkamp <marc@gsites.de> | 2022-05-26 14:49:32 +0200 |
commit | e140e1b54da721a660f2eb9d58a106b7b3ff2f00 (patch) | |
tree | 8e1f630f733e9b323b30277094e447d298dab89d | |
parent | e1be22df61b9d545b7af3d8990603f4782eecced (diff) | |
download | bottle-e140e1b54da721a660f2eb9d58a106b7b3ff2f00.tar.gz |
Gracefully handle errors during early request binding.
-rw-r--r-- | bottle.py | 16 |
1 files changed, 9 insertions, 7 deletions
@@ -848,17 +848,19 @@ class Bottle(object): return tob(template(ERROR_PAGE_TEMPLATE, e=res)) def _handle(self, environ): - path = environ['bottle.raw_path'] = environ['PATH_INFO'] - if py3k: - try: - environ['PATH_INFO'] = path.encode('latin1').decode('utf8') - except UnicodeError: - return HTTPError(400, 'Invalid path string. Expected UTF-8') - try: + environ['bottle.app'] = self request.bind(environ) response.bind() + + path = environ['bottle.raw_path'] = environ['PATH_INFO'] + if py3k: + try: + environ['PATH_INFO'] = path.encode('latin1').decode('utf8') + except UnicodeError: + return HTTPError(400, 'Invalid path string. Expected UTF-8') + try: self.trigger_hook('before_request') route, args = self.router.match(environ) |