Include super dumb http file server

For index.html, other files can be added, but everything has to be hard-coded (mimetype included)
master
pictuga 2014-05-18 12:34:23 +02:00
parent c41a1fe226
commit e8e7f170a6
1 changed files with 27 additions and 0 deletions

View File

@ -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):