Improve file detection in web server

master
pictuga 2015-08-28 19:15:40 +02:00
parent 6741a408dd
commit ffda3fac7e
1 changed files with 6 additions and 3 deletions

View File

@ -621,12 +621,15 @@ def cgi_wrapper(environ, start_response):
if url == '': if url == '':
url = 'index.html' url = 'index.html'
if os.path.isfile(url): try:
body = open(path, 'rb').read()
headers['status'] = '200 OK' headers['status'] = '200 OK'
headers['content-type'] = files[url] headers['content-type'] = files[url]
start_response(headers['status'], list(headers.items())) start_response(headers['status'], list(headers.items()))
return open(url, 'rb').read() return body
else:
except IOError:
headers['status'] = '404 Not found' headers['status'] = '404 Not found'
start_response(headers['status'], list(headers.items())) start_response(headers['status'], list(headers.items()))
return '' return ''