def http(req, sock_factory, timeout=None): t = time.time() tout = conn.set_timeout(timeout) hostname, port, uri = parse_target(req.url) reqx = copy.copy(req) reqx.uri = uri reqx.headers = [(h, v) for h, v in req.headers if not h.startswith('Proxy')] with sock_factory.socket() as sock: sock.connect((hostname, port)) stream1 = sock.makefile() if VERBOSE: req.debug() tout(reqx.send_header)(stream1) streamcopy(reqx, req.stream, stream1, tout) stream1.flush() res = recv_msg(stream1, HttpResponse) if VERBOSE: res.debug() tout(res.send_header)(req.stream) hasbody = req.method.upper() != 'HEAD' and res.code not in CODE_NOBODY streamcopy(res, stream1, req.stream, tout, hasbody) req.stream.flush() res.connection = req.get_header('Proxy-Connection', '').lower() == 'keep-alive' and\ res.get_header('Connection', 'close').lower() != 'close' logger.debug('%s with %d in %0.2f, %s' % ( req.uri.split('?', 1)[0], res.code, time.time() - t, 'keep' if res.connection else 'close')) return res
def http(req, sock_factory, timeout=None): t = time.time() tout = conn.set_timeout(timeout) hostname, port, uri = parse_target(req.url) reqx = copy.copy(req) reqx.uri = uri reqx.headers = [(h, v) for h, v in req.headers if not h.startswith('Proxy')] with sock_factory.socket() as sock: sock.connect((hostname, port)) stream1 = sock.makefile() if VERBOSE: req.debug() tout(reqx.send_header)(stream1) streamcopy(reqx, req.stream, stream1, tout) stream1.flush() res = recv_msg(stream1, HttpResponse) if VERBOSE: res.debug() tout(res.send_header)(req.stream) hasbody = req.method.upper() != 'HEAD' and res.code not in CODE_NOBODY streamcopy(res, stream1, req.stream, tout, hasbody) req.stream.flush() res.connection = req.get_header('Proxy-Connection', '').lower() == 'keep-alive' and\ res.get_header('Connection', 'close').lower() != 'close' logger.debug('%s with %d in %0.2f, %s' % (req.uri.split('?', 1)[0], res.code, time.time() - t, 'keep' if res.connection else 'close')) return res
def loadconfig(self): self.config = import_config(self.cfgs, self.env) self.proxy_auth = proxy.get_proxy_auth(self.config.get('users')) self.proxies = self.config.get('proxies', None) if self.proxies is None: self.proxies = [] if self.config.get('max_conn', None): self.proxies.extend(map(self.ssh2proxy, self.config['sshs'])) self.upstream = self.config.get('upstream') if self.dns is not None: self.dns.stop() self.dns = self.config.get('dnsserver') dnsport = self.config.get('dnsport', None) if dnsport: self.dns.runserver(dnsport) self.dofilter = self.config.get('dofilter') self.whitenf = self.config.get('whitenets') self.blacknf = self.config.get('blacknets') self.direct = conn.DirectManager(self.dns) self.func_connect = conn.set_timeout(self.config.get('conn_tout'))(proxy.connect) self.func_http = conn.set_timeout(self.config.get('http_tout'))(proxy.http)
def loadconfig(self): self.config = import_config(self.cfgs, self.env) self.proxy_auth = proxy.get_proxy_auth(self.config.get('users')) self.proxies = self.config.get('proxies', None) if self.proxies is None: self.proxies = [] if self.config.get('max_conn', None): self.proxies.extend(map(self.ssh2proxy, self.config['sshs'])) self.upstream = self.config.get('upstream') if self.dns is not None: self.dns.stop() self.dns = self.config.get('dnsserver') dnsport = self.config.get('dnsport', None) if dnsport: self.dns.runserver(dnsport) self.dofilter = self.config.get('dofilter') self.whitenf = self.config.get('whitenets') self.blacknf = self.config.get('blacknets') self.direct = conn.DirectManager(self.dns) self.func_connect = conn.set_timeout(self.config.get('conn_tout'))( proxy.connect) self.func_http = conn.set_timeout(self.config.get('http_tout'))( proxy.http)