def rewrite_response(self, resp, extra): try: if extra.get('rewrite_response', False): parser = HttpStream(resp, decompress=True) rw = RewriteResponse(parser, resp, extra) rw.execute() else: parser = HttpStream(resp) headers = parser.headers() headers['connection'] = 'close' new_headers = headers_lines(parser, headers) resp.writeall("".join(new_headers) + "\r\n") body = parser.body_file() send_body(resp, body, parser.is_chunked()) except (socket.error, NoMoreData, ParserError): pass
def rewrite_request(req): try: while True: parser = HttpStream(req) headers = parser.headers() parsed_url = urlparse.urlparse(parser.url()) is_ssl = parsed_url.scheme == "https" host = get_host(parse_address(parsed_url.netloc, 80), is_ssl=is_ssl) headers['Host'] = host headers['Connection'] = 'close' if 'Proxy-Connection' in headers: del headers['Proxy-Connection'] location = urlparse.urlunparse( ('', '', parsed_url.path, parsed_url.params, parsed_url.query, parsed_url.fragment)) httpver = "HTTP/%s" % ".".join(map(str, parser.version())) new_headers = [ "%s %s %s\r\n" % (parser.method(), location, httpver) ] new_headers.extend(["%s: %s\r\n" % (hname, hvalue) \ for hname, hvalue in headers.items()]) req.writeall(bytes("".join(new_headers) + "\r\n")) body = parser.body_file() send_body(req, body, parser.is_chunked()) except (socket.error, NoMoreData, ParserError): pass
def rewrite_request(req): try: while True: parser = HttpStream(req) headers = parser.headers() parsed_url = urlparse.urlparse(parser.url()) is_ssl = parsed_url.scheme == "https" host = get_host(parse_address(parsed_url.netloc, 80), is_ssl=is_ssl) headers['Host'] = host headers['Connection'] = 'close' if 'Proxy-Connection' in headers: del headers['Proxy-Connection'] location = urlparse.urlunparse(('', '', parsed_url.path, parsed_url.params, parsed_url.query, parsed_url.fragment)) httpver = "HTTP/%s" % ".".join(map(str, parser.version())) new_headers = ["%s %s %s\r\n" % (parser.method(), location, httpver)] new_headers.extend(["%s: %s\r\n" % (hname, hvalue) \ for hname, hvalue in headers.items()]) req.writeall(bytes("".join(new_headers) + "\r\n")) body = parser.body_file() send_body(req, body, parser.is_chunked()) except (socket.error, NoMoreData, ParserError): pass