morss: cgi_dispatcher to be able to create extra functions

master
pictuga 2020-04-04 16:35:16 +02:00
parent a8a90cf414
commit 1653394cf7
1 changed files with 17 additions and 0 deletions

View File

@ -651,6 +651,21 @@ def cgi_file_handler(environ, start_response, app):
return app(environ, start_response) return app(environ, start_response)
dispatch_table = {
}
@middleware
def cgi_dispatcher(environ, start_response, app):
url, options = cgi_parse_environ(environ)
for key in dispatch_table.keys():
if key in options:
return dispatch_table[key](environ, start_response)
return app(environ, start_response)
@middleware @middleware
def cgi_error_handler(environ, start_response, app): def cgi_error_handler(environ, start_response, app):
try: try:
@ -706,6 +721,7 @@ def main():
# mod_cgi # mod_cgi
app = cgi_app app = cgi_app
app = cgi_dispatcher(app)
app = cgi_error_handler(app) app = cgi_error_handler(app)
app = cgi_encode(app) app = cgi_encode(app)
@ -727,6 +743,7 @@ def main():
app = cgi_app app = cgi_app
app = cgi_file_handler(app) app = cgi_file_handler(app)
app = cgi_dispatcher(app)
app = cgi_error_handler(app) app = cgi_error_handler(app)
app = cgi_encode(app) app = cgi_encode(app)