MCPcopy
hub / github.com/coleifer/sqlite-web / PrefixMiddleware

Class PrefixMiddleware

sqlite_web/sqlite_web.py:1389–1402  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1387
1388
1389class PrefixMiddleware(object):
1390 def __init__(self, app, prefix):
1391 self.app = app
1392 self.prefix = '/%s' % prefix.strip('/')
1393 self.prefix_len = len(self.prefix)
1394
1395 def __call__(self, environ, start_response):
1396 if environ['PATH_INFO'].startswith(self.prefix):
1397 environ['PATH_INFO'] = environ['PATH_INFO'][self.prefix_len:]
1398 environ['SCRIPT_NAME'] = self.prefix
1399 return self.app(environ, start_response)
1400 else:
1401 start_response('404', [('Content-Type', 'text/plain')])
1402 return ['URL does not match application prefix.'.encode()]
1403
1404#
1405# Script options.

Callers 1

initialize_appFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected