You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

14 lines
560 B
Python

2 years ago
class PrefixMiddleware(object):
2 years ago
def __init__(self, app, prefix=""):
2 years ago
self.app = app
self.prefix = prefix
def __call__(self, environ, start_response):
2 years ago
if environ["PATH_INFO"].startswith(self.prefix):
environ["PATH_INFO"] = environ["PATH_INFO"][len(self.prefix) :]
environ["SCRIPT_NAME"] = self.prefix
2 years ago
return self.app(environ, start_response)
else:
2 years ago
start_response("404", [("Content-Type", "text/plain")])
2 years ago
return ["This url does not belong to the app.".encode()]