# HG changeset patch # User Goffi # Date 1561574210 -7200 # Node ID a15ac511390ca143eb0842fba7f65c4523dc5c4e # Parent 5e67c256477947e522bc716cf764a2c28d9cbbb4 server: changed defaultType for File resources to "application/octet-stream" instead of "text/html" diff -r 5e67c2564779 -r a15ac511390c libervia/server/server.py --- 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