Skip to content

Commit

Permalink
Merge pull request #593 from TaykYoku/v4r3_checkRouting
Browse files Browse the repository at this point in the history
[v4r3] check routing regex
  • Loading branch information
chrisburr authored Oct 25, 2021
2 parents b45022d + 95222bd commit 80e28c5
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/WebAppDIRAC/Core/HandlerMgr.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@


class HandlerMgr(object):
"""This class prepares portal application handlers and forms their routing using regular expressions,
see https://docs.python.org/3/library/re.html
"""

__metaclass__ = DIRACSingleton

def __init__(self, handlersLocation, baseURL="/"):
Expand All @@ -38,7 +42,11 @@ def __init__(self, handlersLocation, baseURL="/"):
self.__handlersLocation = handlersLocation
self.__routes = []
self.__handlers = []
# The following regular expression describes two capturing groups from the incoming request path:
# 1) the DIRAC setup
# 2) the DIRAC user group
self.__setupGroupRE = r"(?:/s:([\w-]*)/g:([\w.-]*))?"
# Describes the same, only as non-capturing groups.
self.__shySetupGroupRE = r"(?:/s:(?:[\w-]*)/g:(?:[\w.-]*))?"
self.log = gLogger.getSubLogger("Routing")

Expand Down Expand Up @@ -112,7 +120,13 @@ def __calculateRoutes(self):
baseRoute = "/%s%s" % (self.__baseURL or "", baseRoute)
# Set properly the LOCATION after calculating where it is with helpers to add group and setup later
handler.LOCATION = handlerRoute
handler.PATH_RE = re.compile("%s(%s/[A-z0-9_-]*)" % (baseRoute, handlerRoute))
# Add a pattern that points to the target method.
# Note that there are handlers with an index method.
# It responds to the request without specifying a method.
# The special characters "*" helps to take into account such a case,
# see https://docs.python.org/3/library/re.html#regular-expression-syntax.
# E.g .: /DIRAC/ -> RootHandler.web_index
handler.PATH_RE = re.compile("%s(%s/[A-z0-9_]*)" % (baseRoute, handlerRoute))
handler.URLSCHEMA = "/%s%%(setup)s%%(group)s%%(location)s/%%(action)s" % (self.__baseURL)
if issubclass(handler, WebSocketHandler):
handler.PATH_RE = re.compile("%s(%s)" % (baseRoute, handlerRoute))
Expand Down

0 comments on commit 80e28c5

Please sign in to comment.