Skip to content

Commit

Permalink
Gracefully handle errors during early request binding.
Browse files Browse the repository at this point in the history
  • Loading branch information
defnull committed May 26, 2022
1 parent e1be22d commit e140e1b
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions bottle.py
Original file line number Diff line number Diff line change
Expand Up @@ -848,17 +848,19 @@ def default_error_handler(self, res):
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)
Expand Down

0 comments on commit e140e1b

Please sign in to comment.