comparison libervia/server/server.py @ 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 ba45dcdbeeaf
children b300eaec53b6
comparison
equal deleted inserted replaced
1195:5e67c2564779 1196:a15ac511390c
131 server.Session.touch(self) 131 server.Session.touch(self)
132 132
133 133
134 class ProtectedFile(static.File): 134 class ProtectedFile(static.File):
135 """A static.File class which doesn't show directory listing""" 135 """A static.File class which doesn't show directory listing"""
136
137 def __init__(self, *args, **kwargs):
138 if "defaultType" not in kwargs and len(args) < 2:
139 # defaultType is second positional argument, and Twisted uses it
140 # in File.createSimilarFile, so we set kwargs only if it is missing
141 # in kwargs and it is not in a positional argument
142 kwargs["defaultType"] = "application/octet-stream"
143 super(ProtectedFile, self).__init__(*args, **kwargs)
136 144
137 def directoryListing(self): 145 def directoryListing(self):
138 return web_resource.NoResource() 146 return web_resource.NoResource()
139 147
140 148
310 current.putChild(segment, resource) 318 current.putChild(segment, resource)
311 current = resource 319 current = resource
312 resource_class = ( 320 resource_class = (
313 ProtectedFile if new_data.get("protected", True) else static.File 321 ProtectedFile if new_data.get("protected", True) else static.File
314 ) 322 )
315 current.putChild(last_segment, resource_class(path)) 323 current.putChild(
324 last_segment,
325 resource_class(path, defaultType="application/octet-stream")
326 )
316 log.info(u"[{host_name}] Added redirection from /{old} to file system " 327 log.info(u"[{host_name}] Added redirection from /{old} to file system "
317 u"path {path}".format(host_name=self.host_name, 328 u"path {path}".format(host_name=self.host_name,
318 old=old.decode("utf-8"), 329 old=old.decode("utf-8"),
319 path=path.decode("utf-8"))) 330 path=path.decode("utf-8")))
320 continue # we don't want to use redirection system, so we continue here 331 continue # we don't want to use redirection system, so we continue here
1929 site_path, auto_add=True, recursive=True, 1940 site_path, auto_add=True, recursive=True,
1930 callback=LiberviaPage.onFileChange, site_root=res, 1941 callback=LiberviaPage.onFileChange, site_root=res,
1931 site_path=site_path) 1942 site_path=site_path)
1932 tasks_manager = TasksManager(self, res) 1943 tasks_manager = TasksManager(self, res)
1933 yield tasks_manager.runTasks() 1944 yield tasks_manager.runTasks()
1934 res.putChild(C.BUILD_DIR, static.File(self.getBuildPath(site_name))) 1945 res.putChild(
1946 C.BUILD_DIR,
1947 static.File(self.getBuildPath(site_name),
1948 defaultType="application/octet-stream"),
1949 )
1935 1950
1936 LiberviaPage.importPages(self, res) 1951 LiberviaPage.importPages(self, res)
1937 # FIXME: default pages are accessible if not overriden by external website 1952 # FIXME: default pages are accessible if not overriden by external website
1938 # while necessary for login or re-using existing pages 1953 # while necessary for login or re-using existing pages
1939 # we may want to disable access to the page by direct URL 1954 # we may want to disable access to the page by direct URL