Extract httputils.redirect
This commit is contained in:
parent
1336c02079
commit
d1532aa466
@ -197,10 +197,8 @@ class Application(ApplicationPartDelete, ApplicationPartHead,
|
|||||||
location = base_prefix + path
|
location = base_prefix + path
|
||||||
logger.info("Redirecting to sanitized path: %r ==> %r",
|
logger.info("Redirecting to sanitized path: %r ==> %r",
|
||||||
base_prefix + unsafe_path, location)
|
base_prefix + unsafe_path, location)
|
||||||
return response(
|
return response(*httputils.redirect(
|
||||||
client.MOVED_PERMANENTLY,
|
location, client.MOVED_PERMANENTLY))
|
||||||
{"Location": location, "Content-Type": "text/plain"},
|
|
||||||
"Redirected to %s" % location)
|
|
||||||
logger.debug("Sanitized path: %r", path)
|
logger.debug("Sanitized path: %r", path)
|
||||||
|
|
||||||
# Get function corresponding to method
|
# Get function corresponding to method
|
||||||
|
@ -62,10 +62,7 @@ class ApplicationPartGet(ApplicationBase):
|
|||||||
"""Manage GET request."""
|
"""Manage GET request."""
|
||||||
# Redirect to .web if the root URL is requested
|
# Redirect to .web if the root URL is requested
|
||||||
if not pathutils.strip_path(path):
|
if not pathutils.strip_path(path):
|
||||||
location = ".web"
|
return httputils.redirect(".web")
|
||||||
return (client.FOUND,
|
|
||||||
{"Location": location, "Content-Type": "text/plain"},
|
|
||||||
"Redirected to %s" % location)
|
|
||||||
# Dispatch .web URL to web module
|
# Dispatch .web URL to web module
|
||||||
if path == "/.web" or path.startswith("/.web/"):
|
if path == "/.web" or path.startswith("/.web/"):
|
||||||
return self._web.get(environ, base_prefix, path, user)
|
return self._web.get(environ, base_prefix, path, user)
|
||||||
|
@ -114,3 +114,9 @@ def read_request_body(configuration: "config.Configuration",
|
|||||||
read_raw_request_body(configuration, environ))
|
read_raw_request_body(configuration, environ))
|
||||||
logger.debug("Request content:\n%s", content)
|
logger.debug("Request content:\n%s", content)
|
||||||
return content
|
return content
|
||||||
|
|
||||||
|
|
||||||
|
def redirect(location: str, status: int = client.FOUND) -> types.WSGIResponse:
|
||||||
|
return (status,
|
||||||
|
{"Location": location, "Content-Type": "text/plain"},
|
||||||
|
"Redirected to %s" % location)
|
||||||
|
@ -75,10 +75,7 @@ class Web(web.BaseWeb):
|
|||||||
path, e, exc_info=True)
|
path, e, exc_info=True)
|
||||||
return httputils.NOT_FOUND
|
return httputils.NOT_FOUND
|
||||||
if os.path.isdir(filesystem_path) and not path.endswith("/"):
|
if os.path.isdir(filesystem_path) and not path.endswith("/"):
|
||||||
location = posixpath.basename(path) + "/"
|
return httputils.redirect(posixpath.basename(path) + "/")
|
||||||
return (client.FOUND,
|
|
||||||
{"Location": location, "Content-Type": "text/plain"},
|
|
||||||
"Redirected to %s" % location)
|
|
||||||
if os.path.isdir(filesystem_path):
|
if os.path.isdir(filesystem_path):
|
||||||
filesystem_path = os.path.join(filesystem_path, "index.html")
|
filesystem_path = os.path.join(filesystem_path, "index.html")
|
||||||
if not os.path.isfile(filesystem_path):
|
if not os.path.isfile(filesystem_path):
|
||||||
|
Loading…
Reference in New Issue
Block a user