changed dispatched by path example

This commit is contained in:
pavithra-m13 2023-08-12 15:30:47 +05:30 committed by GitHub
parent b1385919be
commit 4bf507bcd5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -146,7 +146,7 @@ the ``Host`` header to figure out the subdomain one simply looks at the
request path up to the first slash::
from threading import Lock
from werkzeug.wsgi import pop_path_info, peek_path_info
from wsgiref.util import shift_path_info
class PathDispatcher:
@ -166,13 +166,19 @@ request path up to the first slash::
return app
def __call__(self, environ, start_response):
app = self.get_application(peek_path_info(environ))
app = self.get_application(self._peek_path_info(environ))
if app is not None:
pop_path_info(environ)
shift_path_info(environ)
else:
app = self.default_app
return app(environ, start_response)
def _peek_path_info(self, environ):
segments = environ.get("PATH_INFO", "").lstrip("/").split("/", 1)
if segments:
return segments[0]
return None
The big difference between this and the subdomain one is that this one
falls back to another application if the creator function returns ``None``::