Edgewall Software

Ticket #3655: irequestfilter_patch_3689.2.diff

File irequestfilter_patch_3689.2.diff, 2.1 KB (added by cboos, 2 years ago)

Slightly modified version: trap errors raised by calls to prepare_request()

  • trac/web/api.py

     
    467467    requests, before and/or after they are processed by the main handler.""" 
    468468 
    469469    def pre_process_request(req, handler): 
    470         """Do any pre-processing the request might need; typically adding 
    471         values to req.hdf, or redirecting. 
     470        """Called after initial handler selection, and can be used to change 
     471        the selected handler or redirect request. 
    472472         
    473473        Always returns the request handler, even if unchanged. 
    474474        """ 
    475475 
     476    def prepare_request(req, handler): 
     477        """Do any pre-processing before actual processing; typically adding 
     478        values to req.hdf, req.environ or similar. 
     479         
     480        If no handler is found or the handler does not use templates, 
     481        req.hdf will be None. 
     482         
     483        Always returns the request object, even if unchanged. 
     484        """ 
     485 
    476486    def post_process_request(req, template, content_type): 
    477487        """Do any post-processing the request might need; typically adding 
    478488        values to req.hdf, or changing template or mime type. 
  • trac/web/main.py

     
    206206                req.hdf = HDFWrapper(loadpaths=chrome.get_all_templates_dirs()) 
    207207                populate_hdf(req.hdf, self.env, req) 
    208208                chrome.populate_hdf(req, chosen_handler) 
     209            else: 
     210                req.hdf = None 
    209211        except: 
    210212            req.hdf = None # revert to sending plaintext error 
    211213            if not early_error: 
     
    217219        # Process the request and render the template 
    218220        try: 
    219221            try: 
     222                for f in self.filters: 
     223                    req = f.prepare_request(req, chosen_handler) 
     224 
    220225                resp = chosen_handler.process_request(req) 
    221226                if resp: 
    222227                    for filter_ in reversed(self.filters):