summaryrefslogtreecommitdiffstats
path: root/deluge/ui/web/server.py
diff options
context:
space:
mode:
authorCalum Lind <calumlind+deluge@gmail.com>2017-03-13 13:53:01 +0000
committerCalum Lind <calumlind+deluge@gmail.com>2017-03-15 23:12:36 +0000
commit321677e05a7d24e3a0c76012b588671a03bdac54 (patch)
treee2e81146308e2c060727604703c6695237c9ce6d /deluge/ui/web/server.py
parent960f3a6552a47549ef46dee5f9579ccf317d7bbf (diff)
downloaddeluge-321677e05a7d24e3a0c76012b588671a03bdac54.tar.gz
deluge-321677e05a7d24e3a0c76012b588671a03bdac54.tar.bz2
deluge-321677e05a7d24e3a0c76012b588671a03bdac54.zip
[WebUI] Return 404.html for files not found
- This ensures a proper request response is returned.
Diffstat (limited to 'deluge/ui/web/server.py')
-rw-r--r--deluge/ui/web/server.py44
1 files changed, 23 insertions, 21 deletions
diff --git a/deluge/ui/web/server.py b/deluge/ui/web/server.py
index a02609f53..f712be1e7 100644
--- a/deluge/ui/web/server.py
+++ b/deluge/ui/web/server.py
@@ -140,14 +140,15 @@ class Render(resource.Resource):
request.setResponseCode(http.INTERNAL_SERVER_ERROR)
return ''
- if request.render_file not in self.template_files:
+ if request.render_file in self.template_files:
+ request.setResponseCode(http.OK)
+ filename = os.path.join('render', request.render_file)
+ else:
request.setResponseCode(http.NOT_FOUND)
- return '<h1>404 - Not Found</h1>'
+ filename = os.path.join('render', '404.html')
- filename = os.path.join('render', request.render_file)
- template = Template(filename=rpath(filename))
request.setHeader(b'content-type', b'text/html')
- request.setResponseCode(http.OK)
+ template = Template(filename=rpath(filename))
return compress(template.render(), request)
@@ -233,23 +234,22 @@ class LookupResource(resource.Resource, component.Component):
log.debug('Requested path: %s', request.lookup_path)
path = os.path.dirname(request.lookup_path)
- if path not in self.__paths:
- request.setResponseCode(http.NOT_FOUND)
- return '<h1>404 - Not Found</h1>'
-
- filename = os.path.basename(request.path)
- for directory in self.__paths[path]:
- if os.path.join(directory, filename):
- path = os.path.join(directory, filename)
- log.debug('Serving path: %s', path)
- mime_type = mimetypes.guess_type(path)
- request.setHeader(b'content-type', mime_type[0])
- with open(path, 'rb') as _file:
- data = _file.read()
- return compress(data, request)
+ if path in self.__paths:
+ filename = os.path.basename(request.path)
+ for directory in self.__paths[path]:
+ if os.path.join(directory, filename):
+ path = os.path.join(directory, filename)
+ log.debug('Serving path: %s', path)
+ mime_type = mimetypes.guess_type(path)
+ request.setHeader(b'content-type', mime_type[0])
+ with open(path, 'rb') as _file:
+ data = _file.read()
+ return compress(data, request)
request.setResponseCode(http.NOT_FOUND)
- return '<h1>404 - Not Found</h1>'
+ request.setHeader(b'content-type', b'text/html')
+ template = Template(filename=rpath(os.path.join('render', '404.html')))
+ return compress(template.render(), request)
class ScriptResource(resource.Resource, component.Component):
@@ -409,7 +409,9 @@ class ScriptResource(resource.Resource, component.Component):
return compress(data, request)
request.setResponseCode(http.NOT_FOUND)
- return '<h1>404 - Not Found</h1>'
+ request.setHeader(b'content-type', b'text/html')
+ template = Template(filename=rpath(os.path.join('render', '404.html')))
+ return compress(template.render(), request)
class TopLevel(resource.Resource):