wsgi: use data_files helper
continuous-integration/drone/push Build was killed
Details
continuous-integration/drone/push Build was killed
Details
parent
3392ae3973
commit
727d14e539
|
@ -36,6 +36,7 @@ except ImportError:
|
||||||
from . import caching, crawler, readabilite
|
from . import caching, crawler, readabilite
|
||||||
from .morss import (DELAY, TIMEOUT, FeedFetch, FeedFormat, FeedGather,
|
from .morss import (DELAY, TIMEOUT, FeedFetch, FeedFormat, FeedGather,
|
||||||
MorssException, Options, log)
|
MorssException, Options, log)
|
||||||
|
from .util import data_path
|
||||||
|
|
||||||
PORT = int(os.getenv('PORT', 8000))
|
PORT = int(os.getenv('PORT', 8000))
|
||||||
|
|
||||||
|
@ -167,26 +168,20 @@ def cgi_file_handler(environ, start_response, app):
|
||||||
|
|
||||||
if re.match(r'^/?([a-zA-Z0-9_-][a-zA-Z0-9\._-]+/?)*$', url):
|
if re.match(r'^/?([a-zA-Z0-9_-][a-zA-Z0-9\._-]+/?)*$', url):
|
||||||
# if it is a legitimate url (no funny relative paths)
|
# if it is a legitimate url (no funny relative paths)
|
||||||
paths = [
|
try:
|
||||||
os.path.join(sys.prefix, 'share/morss/www', url),
|
f = open(data_path(url), 'rb')
|
||||||
os.path.join(os.path.dirname(__file__), '../www', url)
|
|
||||||
]
|
|
||||||
|
|
||||||
for path in paths:
|
except IOError:
|
||||||
try:
|
# problem with file (cannot open or not found)
|
||||||
f = open(path, 'rb')
|
continue
|
||||||
|
|
||||||
except IOError:
|
else:
|
||||||
# problem with file (cannot open or not found)
|
# file successfully open
|
||||||
continue
|
headers = {}
|
||||||
|
headers['status'] = '200 OK'
|
||||||
else:
|
headers['content-type'] = mimetypes.guess_type(path)[0] or 'application/octet-stream'
|
||||||
# file successfully open
|
start_response(headers['status'], list(headers.items()))
|
||||||
headers = {}
|
return wsgiref.util.FileWrapper(f)
|
||||||
headers['status'] = '200 OK'
|
|
||||||
headers['content-type'] = mimetypes.guess_type(path)[0] or 'application/octet-stream'
|
|
||||||
start_response(headers['status'], list(headers.items()))
|
|
||||||
return wsgiref.util.FileWrapper(f)
|
|
||||||
|
|
||||||
# regex didn't validate or no file found
|
# regex didn't validate or no file found
|
||||||
return app(environ, start_response)
|
return app(environ, start_response)
|
||||||
|
|
Loading…
Reference in New Issue