Mercurial > libervia-web
changeset 1196:a15ac511390c
server: changed defaultType for File resources to "application/octet-stream" instead of "text/html"
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 26 Jun 2019 20:36:50 +0200 |
parents | 5e67c2564779 |
children | b251c8bb6776 |
files | libervia/server/server.py |
diffstat | 1 files changed, 17 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/libervia/server/server.py Fri Jun 14 12:51:03 2019 +0200 +++ b/libervia/server/server.py Wed Jun 26 20:36:50 2019 +0200 @@ -134,6 +134,14 @@ class ProtectedFile(static.File): """A static.File class which doesn't show directory listing""" + def __init__(self, *args, **kwargs): + if "defaultType" not in kwargs and len(args) < 2: + # defaultType is second positional argument, and Twisted uses it + # in File.createSimilarFile, so we set kwargs only if it is missing + # in kwargs and it is not in a positional argument + kwargs["defaultType"] = "application/octet-stream" + super(ProtectedFile, self).__init__(*args, **kwargs) + def directoryListing(self): return web_resource.NoResource() @@ -312,7 +320,10 @@ resource_class = ( ProtectedFile if new_data.get("protected", True) else static.File ) - current.putChild(last_segment, resource_class(path)) + current.putChild( + last_segment, + resource_class(path, defaultType="application/octet-stream") + ) log.info(u"[{host_name}] Added redirection from /{old} to file system " u"path {path}".format(host_name=self.host_name, old=old.decode("utf-8"), @@ -1931,7 +1942,11 @@ site_path=site_path) tasks_manager = TasksManager(self, res) yield tasks_manager.runTasks() - res.putChild(C.BUILD_DIR, static.File(self.getBuildPath(site_name))) + res.putChild( + C.BUILD_DIR, + static.File(self.getBuildPath(site_name), + defaultType="application/octet-stream"), + ) LiberviaPage.importPages(self, res) # FIXME: default pages are accessible if not overriden by external website