diff --git a/deluge/ui/web/render/404.html b/deluge/ui/web/render/404.html new file mode 100644 index 000000000..8624de46b --- /dev/null +++ b/deluge/ui/web/render/404.html @@ -0,0 +1,10 @@ + + + + Deluge: Web UI ${version} + + +

Error 404 - Page Not Found

+ The requested template file was not found. + + 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 '

404 - Not Found

' + 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 '

404 - Not Found

' - - 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 '

404 - Not Found

' + 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 '

404 - Not Found

' + 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):