Edgewall Software

Ticket #1855: preprocessor_r2165.patch

File preprocessor_r2165.patch, 1.8 KB (added by Bruce Christensen <trac@…>, 7 years ago)
  • trac/web/api.py

     
    239239        """ 
    240240 
    241241 
     242class IRequestPreprocessor(Interface): 
     243    """Extension point interface for request preprocessors.""" 
     244 
     245    def preprocess_request(req): 
     246        """Preprocess the request. This allows any last-minute processing before 
     247        the request is dispatched to the request handler. 
     248        """ 
     249 
     250 
    242251def absolute_url(req, path=None): 
    243252    """Reconstruct the absolute URL of the given request. 
    244253     
  • trac/web/main.py

     
    2323from trac.perm import PermissionCache, PermissionError 
    2424from trac.util import escape, enum 
    2525from trac.web.api import absolute_url, Request, RequestDone, IAuthenticator, \ 
    26                          IRequestHandler 
     26                         IRequestPreprocessor, IRequestHandler 
    2727from trac.web.chrome import Chrome 
    2828from trac.web.clearsilver import HDFWrapper 
    2929from trac.web.href import Href 
     
    5959    """Component responsible for dispatching requests to registered handlers.""" 
    6060 
    6161    authenticators = ExtensionPoint(IAuthenticator) 
     62    preprocessors = ExtensionPoint(IRequestPreprocessor) 
    6263    handlers = ExtensionPoint(IRequestHandler) 
    6364 
    6465    def authenticate(self, req): 
     
    99100 
    100101        chrome.populate_hdf(req, chosen_handler) 
    101102 
     103        for preprocessor in self.preprocessors: 
     104            preprocessor.preprocess_request(req) 
     105 
    102106        if not chosen_handler: 
    103107            # FIXME: Should return '404 Not Found' to the client 
    104108            raise TracError, 'No handler matched request to %s' % req.path_info