mirror of
https://git.deluge-torrent.org/deluge
synced 2025-08-02 22:48:40 +00:00
[WebUI] Return 404.html for files not found
- This ensures a proper request response is returned.
This commit is contained in:
parent
960f3a6552
commit
321677e05a
2 changed files with 33 additions and 21 deletions
10
deluge/ui/web/render/404.html
Normal file
10
deluge/ui/web/render/404.html
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||||
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||||
|
<head>
|
||||||
|
<title>Deluge: Web UI ${version}</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Error 404 - Page Not Found</h1>
|
||||||
|
<b>The requested template file was not found.</b>
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -140,14 +140,15 @@ class Render(resource.Resource):
|
||||||
request.setResponseCode(http.INTERNAL_SERVER_ERROR)
|
request.setResponseCode(http.INTERNAL_SERVER_ERROR)
|
||||||
return ''
|
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)
|
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.setHeader(b'content-type', b'text/html')
|
||||||
request.setResponseCode(http.OK)
|
template = Template(filename=rpath(filename))
|
||||||
return compress(template.render(), request)
|
return compress(template.render(), request)
|
||||||
|
|
||||||
|
|
||||||
|
@ -233,23 +234,22 @@ class LookupResource(resource.Resource, component.Component):
|
||||||
log.debug('Requested path: %s', request.lookup_path)
|
log.debug('Requested path: %s', request.lookup_path)
|
||||||
path = os.path.dirname(request.lookup_path)
|
path = os.path.dirname(request.lookup_path)
|
||||||
|
|
||||||
if path not in self.__paths:
|
if path in self.__paths:
|
||||||
request.setResponseCode(http.NOT_FOUND)
|
filename = os.path.basename(request.path)
|
||||||
return '<h1>404 - Not Found</h1>'
|
for directory in self.__paths[path]:
|
||||||
|
if os.path.join(directory, filename):
|
||||||
filename = os.path.basename(request.path)
|
path = os.path.join(directory, filename)
|
||||||
for directory in self.__paths[path]:
|
log.debug('Serving path: %s', path)
|
||||||
if os.path.join(directory, filename):
|
mime_type = mimetypes.guess_type(path)
|
||||||
path = os.path.join(directory, filename)
|
request.setHeader(b'content-type', mime_type[0])
|
||||||
log.debug('Serving path: %s', path)
|
with open(path, 'rb') as _file:
|
||||||
mime_type = mimetypes.guess_type(path)
|
data = _file.read()
|
||||||
request.setHeader(b'content-type', mime_type[0])
|
return compress(data, request)
|
||||||
with open(path, 'rb') as _file:
|
|
||||||
data = _file.read()
|
|
||||||
return compress(data, request)
|
|
||||||
|
|
||||||
request.setResponseCode(http.NOT_FOUND)
|
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):
|
class ScriptResource(resource.Resource, component.Component):
|
||||||
|
@ -409,7 +409,9 @@ class ScriptResource(resource.Resource, component.Component):
|
||||||
return compress(data, request)
|
return compress(data, request)
|
||||||
|
|
||||||
request.setResponseCode(http.NOT_FOUND)
|
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):
|
class TopLevel(resource.Resource):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue