From e8e7f170a68a2f3aeca2eca6b62f143ca196ffb6 Mon Sep 17 00:00:00 2001 From: pictuga Date: Sun, 18 May 2014 12:34:23 +0200 Subject: [PATCH] Include super dumb http file server For index.html, other files can be added, but everything has to be hard-coded (mimetype included) --- morss/morss.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/morss/morss.py b/morss/morss.py index 4cff19d..7c02f05 100644 --- a/morss/morss.py +++ b/morss/morss.py @@ -735,6 +735,33 @@ def cgi_app(environ, start_response): log('done') def cgi_wrapper(environ, start_response): + # simple http server for html and css + files = { + '': 'text/html', + 'index.html': 'text/html'} + + if 'REQUEST_URI' in environ: + url = environ['REQUEST_URI'][1:] + else: + url = environ['PATH_INFO'][1:] + + if url in files: + headers = {} + + if url == '': + url = 'index.html' + + if os.path.isfile(url): + headers['status'] = '200 OK' + headers['content-type'] = files[url] + start_response(headers['status'], headers.items()) + return open(url, 'rb').read() + else: + headers['status'] = '404 Not found' + start_response(headers['status'], headers.items()) + return '' + + # actual morss use try: return cgi_app(environ, start_response) or [] except (KeyboardInterrupt, SystemExit):