def _connect_to_host(self): if self.connect_through_ssl: self.hostname, self.port = self.path.split(':') else: u = urlparse(self.path) if u.scheme != 'http': print 'ERROR Unknown request scheme: %s' % repr(u.scheme) self.hostname = u.hostname self.port = u.port or 80 self.path = urlunparse( ParseResult( scheme='http', netloc='%s' % u.hostname, params=u.params, path=u.path or '/', query=u.query, fragment=u.fragment ) ) # Create a pipe to the remote server self._pipe_socket = ProxySocket( self._proxy_fetcher, chainlength=self.CHAIN, use_ssl=self.connect_through_ssl, DEBUG=self.DEBUG ) self._pipe_socket.connect( (self.hostname, int(self.port)) ) # Wrap socket if SSL is required if self.connect_through_ssl: self._pipe_socket = wrap_socket(self._pipe_socket)
class ProxiedRequestHandler(BaseHTTPRequestHandler): def __init__(self, request, client_address, server): self.connect_through_ssl = False self._proxy_fetcher = server.proxy_fetcher self.CHAIN = server.CHAIN self.DEBUG = server.DEBUG try: BaseHTTPRequestHandler.__init__(self, request, client_address, server) except Exception as e: if server.DEBUG: print e def _connect_to_host(self): if self.connect_through_ssl: self.hostname, self.port = self.path.split(':') else: u = urlparse(self.path) if u.scheme != 'http': print 'ERROR Unknown request scheme: %s' % repr(u.scheme) self.hostname = u.hostname self.port = u.port or 80 self.path = urlunparse( ParseResult( scheme='http', netloc='%s' % u.hostname, params=u.params, path=u.path or '/', query=u.query, fragment=u.fragment ) ) # Create a pipe to the remote server self._pipe_socket = ProxySocket( self._proxy_fetcher, chainlength=self.CHAIN, use_ssl=self.connect_through_ssl, DEBUG=self.DEBUG ) self._pipe_socket.connect( (self.hostname, int(self.port)) ) # Wrap socket if SSL is required if self.connect_through_ssl: self._pipe_socket = wrap_socket(self._pipe_socket) def do_CONNECT(self): self.connect_through_ssl = True try: self._connect_to_host() # http://curl.haxx.se/ca/cacert.pem self.request = wrap_socket( self.request, server_side = True, certfile = self.server.ca[self.path.split(':')[0]], ssl_version=PROTOCOL_TLSv1, ca_certs=os.path.join(os.getcwd(),'cacert.pem') ) except Exception, e: self.send_error(500, str(e)) return # Reload! self.setup() self.ssl_host = 'https://%s' % self.path self.handle_one_request()
def _connect_to_host(self): if self.connect_through_ssl: self.hostname, self.port = self.path.split(":") else: u = urlparse(self.path) if u.scheme != "http": print "ERROR Unknown request scheme: %s" % repr(u.scheme) self.hostname = u.hostname self.port = u.port or 80 self.path = urlunparse( ParseResult( scheme="http", netloc="%s" % u.hostname, params=u.params, path=u.path or "/", query=u.query, fragment=u.fragment, ) ) # Create a pipe to the remote server self._pipe_socket = ProxySocket( self._proxy_fetcher, chainlength=self.CHAIN, use_ssl=self.connect_through_ssl, DEBUG=self.DEBUG ) self._pipe_socket.connect((self.hostname, int(self.port))) # Wrap socket if SSL is required if self.connect_through_ssl: self._pipe_socket = wrap_socket(self._pipe_socket)
class ProxiedRequestHandler(BaseHTTPRequestHandler): def __init__(self, request, client_address, server): self.connect_through_ssl = False self._proxy_fetcher = server.proxy_fetcher self.CHAIN = server.CHAIN self.DEBUG = server.DEBUG try: BaseHTTPRequestHandler.__init__(self, request, client_address, server) except Exception as e: if server.DEBUG: print e def _connect_to_host(self): if self.connect_through_ssl: self.hostname, self.port = self.path.split(":") else: u = urlparse(self.path) if u.scheme != "http": print "ERROR Unknown request scheme: %s" % repr(u.scheme) self.hostname = u.hostname self.port = u.port or 80 self.path = urlunparse( ParseResult( scheme="http", netloc="%s" % u.hostname, params=u.params, path=u.path or "/", query=u.query, fragment=u.fragment, ) ) # Create a pipe to the remote server self._pipe_socket = ProxySocket( self._proxy_fetcher, chainlength=self.CHAIN, use_ssl=self.connect_through_ssl, DEBUG=self.DEBUG ) self._pipe_socket.connect((self.hostname, int(self.port))) # Wrap socket if SSL is required if self.connect_through_ssl: self._pipe_socket = wrap_socket(self._pipe_socket) def do_CONNECT(self): self.connect_through_ssl = True try: self._connect_to_host() # http://curl.haxx.se/ca/cacert.pem self.request = wrap_socket( self.request, server_side=True, certfile=self.server.ca[self.path.split(":")[0]], ssl_version=PROTOCOL_TLSv1, ca_certs=os.path.join(os.getcwd(), "cacert.pem"), ) except Exception, e: self.send_error(500, str(e)) return # Reload! self.setup() self.ssl_host = "https://%s" % self.path self.handle_one_request()