Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/viur/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,12 @@ class Conf(ConfigType):
}
"""Describing the Script module"""

redirect_map = {}
"""Map for redirect Urls"""

redirect_map_advanced_mode = False
"""If True the fnmatch is activated for key match"""

render_html_download_url_expiration: t.Optional[float | int] = None
"""The default duration, for which downloadURLs generated by the html renderer will stay valid"""

Expand Down
16 changes: 16 additions & 0 deletions src/viur/core/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class Router:
The basic control flow is
- Setting up internal variables
- Running the Request validators
- Check the Redirect Map
- Emitting the headers (especially the security related ones)
- Run the TLS check (ensure it's a secure connection or check if the URL is whitelisted)
- Load or initialize a new session
Expand Down Expand Up @@ -271,6 +272,21 @@ def _process(self):

path = self.request.path

if conf.redirect_map:
if conf.redirect_map_advanced_mode:
for k in conf.redirect_map.keys():
if fnmatch.fnmatch(path, k):
self.response.status = "302 Redirect"
self.response.headers['Location'] = conf.redirect_map[k]
self.response.write("Redirect")
return

if redirect_url := conf.redirect_map.get(path):
self.response.status = "302 Redirect"
self.response.headers['Location'] = redirect_url
self.response.write("Redirect")
return

# Add CSP headers early (if any)
if conf.security.content_security_policy and conf.security.content_security_policy["_headerCache"]:
for k, v in conf.security.content_security_policy["_headerCache"].items():
Expand Down