mime-type guessing for /template/render/

This commit is contained in:
Martijn Voncken 2008-07-22 19:24:57 +00:00
parent 276cf262ed
commit adc9902252
2 changed files with 17 additions and 2 deletions

View File

@ -392,8 +392,9 @@ route("/template/static/(.*)", template_static)
class template_render:
"render anything in /render/ dir"
@deco.deluge_page
def GET(self, name):
web.header("Content-type",utils.guess_mime_type(name))
#security : assumes config.get('template') returns a safe subdir.
basepath = os.path.normpath(os.path.join(os.path.dirname(__file__),
'templates/%s/render' % config.get('template')))
@ -402,7 +403,7 @@ class template_render:
#hack detected?
raise Exception("File to render is not located in %s" % basepath)
return web.template.Template(open(filename).read(), filename=filename)()
print web.template.Template(open(filename).read(), filename=filename)()
route("/template/render/(.*)", template_render)
class template_style:

View File

@ -297,3 +297,17 @@ class WebUiError(Exception):
class UnknownTorrentError(WebUiError):
pass
#mime-type guessing :
def guess_mime_type(path):
import posixpath
from mimetypes import types_map as extensions_map
base, ext = posixpath.splitext(path)
if ext in extensions_map:
return extensions_map[ext]
ext = ext.lower()
if ext in extensions_map:
return extensions_map[ext]
else:
return 'application/octet-stream'