def __call__(self, environ, start_response): assert not environ['wsgi.multiprocess'], ( "Leak middleware is not usable in a " "multi-process environment") if self.inupy_config['ipfilter'] and not check_ipfilter(environ, self.inupy_config['ipfilter']): # then we want to filter on ip and this one failed return self.app(environ, start_response) else: req = Request(environ) req.base_path = req.application_url + self.path if (req.path_info.startswith(self.path+'/') or req.path_info == self.path): req.script_name += self.path req.path_info = req.path_info[len(self.path):] return self.dowse(req)(environ, start_response) else: return self.app(environ, start_response)
def __call__(self, environ, start_response): assert not environ['wsgi.multiprocess'], ( "Inupy middleware is not usable in a " "multi-process environment") if self.inupy_config['ipfilter'] and not check_ipfilter(environ, self.inupy_config['ipfilter']): # then we want to filter on ip and this one failed return self.app(environ, start_response) else: req = Request(environ) req.base_path = req.application_url + '/_profiler' if req.path_info_peek() == '_profiler': return self.profiler(req)(environ, start_response) for regex in self.ignored_paths: if regex.match(environ['PATH_INFO']) is not None: return self.app(environ, start_response) return self.run_profile(environ, start_response)
def __call__(self, environ, start_response): req = Request(environ) self.logger.log(self.loglevel, 'request started') response = req.get_response(self.app) if self.inupy_config['ipfilter'] and not check_ipfilter(environ, self.inupy_config['ipfilter']): # then we want to filter on ip and this one failed pass else: self.logger.log(self.loglevel, 'request finished') if 'content-type' in response.headers and \ response.headers['content-type'].startswith('text/html'): controls_ui = self.render_html('/controls.mako', inupy_config=self.inupy_config) replacement = r'<body\1><script type="text/javascript">inupy_js</script>{0}'.format(controls_ui) response.body = re.sub(r'<body([^>]*)>', replacement, response.body) response.body = response.body.replace('inupy_js', get_js_code(self.tmpl_dir)) return response(environ, start_response)
def __call__(self, environ, start_response): if thread: tok = thread.get_ident() else: tok = None req = Request(environ) start = time.time() self.logger.log(self.loglevel, '%s request started for %s', req.method, req.path_info) response = req.get_response(self.app) if self.inupy_config['ipfilter'] and not check_ipfilter(environ, self.inupy_config['ipfilter']): # then we want to filter on ip and this one failed pass else: content_type = response.headers.get('content-type', '') size = len(response.body) self.logger.log(self.loglevel, 'request finished: returned %d bytes of %s', size, content_type) tottime = time.time() - start reqlogs = self.reqhandler.pop_events(tok) if content_type.startswith('text/html'): logbar = self.render_html('/logbar.mako', events=reqlogs, logcolors=self.inupy_config['log_colors'], traceback_colors=self.inupy_config['traceback_colors'], tottime=tottime, start=start) response.body = re.sub(r'<body([^>]*)>', r'<body\1>%s' % logbar, response.body) elif content_type.startswith('application/json'): response.body = self.render_json(response.body, events=reqlogs, logcolors=self.inupy_config['log_colors'], tottime=tottime, start=start) return response(environ, start_response)