Ticket #3655: irequestfilter-r3717.diff
| File irequestfilter-r3717.diff, 3.9 KB (added by cboos, 6 years ago) |
|---|
-
trac/web/api.py
467 467 requests, before and/or after they are processed by the main handler.""" 468 468 469 469 def pre_process_request(req, handler): 470 """ Do any pre-processing the request might need; typically adding471 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. 472 472 473 473 Always returns the request handler, even if unchanged. 474 474 """ -
trac/web/main.py
172 172 chosen_handler = handler 173 173 break 174 174 175 for f in self.filters: 176 chosen_handler = f.pre_process_request(req, chosen_handler) 177 175 chosen_handler = self._pre_process_request(req, chosen_handler) 178 176 except: 179 177 early_error = sys.exc_info() 180 178 … … 201 199 # Prepare HDF for the clearsilver template 202 200 try: 203 201 use_template = getattr(chosen_handler, 'use_template', True) 202 req.hdf = None 204 203 if use_template: 205 204 chrome = Chrome(self.env) 206 205 req.hdf = HDFWrapper(loadpaths=chrome.get_all_templates_dirs()) … … 212 211 raise 213 212 214 213 if early_error: 214 try: 215 self._post_process_request(req) 216 except Exception, e: 217 self.log.exception(e) 215 218 raise early_error[0], early_error[1], early_error[2] 216 219 217 220 # Process the request and render the template 218 221 try: 219 222 try: 220 resp = chosen_handler.process_request(req) 221 if resp: 222 for filter_ in reversed(self.filters): 223 resp = filter_.post_process_request(req, *resp) 224 template, content_type = resp 225 req.display(template, content_type or 'text/html') 226 else: 227 for filter_ in reversed(self.filters): 228 filter_.post_process_request(req, None, None) 223 try: 224 resp = chosen_handler.process_request(req) 225 if resp: 226 template, content_type = \ 227 self._post_process_request(req, *resp) 228 req.display(template, content_type or 'text/html') 229 else: 230 self._post_process_request(req) 231 except: 232 err = sys.exc_info() 233 try: 234 self._post_process_request(req) 235 except Exception, e: 236 self.log.exception(e) 237 raise err[0], err[1], err[2] 229 238 except PermissionError, e: 230 239 raise HTTPForbidden(to_unicode(e)) 231 240 except TracError, e: … … 235 244 if req.session: 236 245 req.session.save() 237 246 247 def _pre_process_request(self, req, chosen_handler): 248 for f in self.filters: 249 chosen_handler = f.pre_process_request(req, chosen_handler) 250 return chosen_handler 251 252 def _post_process_request(self, req, template=None, content_type=None): 253 for f in reversed(self.filters): 254 template, content_type = f.post_process_request(req, template, 255 content_type) 256 return template, content_type 238 257 258 239 259 def dispatch_request(environ, start_response): 240 260 """Main entry point for the Trac web interface. 241 261
