コード例 #1
0
ファイル: spdy_relay.py プロジェクト: JinGeek/fqsocks
 def do_forward(self, client):
     recv_and_parse_request(client)
     if SPDY_3 == self.spdy_client.spdy_version:
         headers = {
             ':method': client.method,
             ':scheme': 'http',
             ':path': client.path,
             ':version': 'HTTP/1.1',
             ':host': client.host
         }
     else:
         headers = {
             'method': client.method,
             'scheme': 'http',
             'url': client.url,
             'version': 'HTTP/1.1',
             'host': client.host
         }
     if self.username and self.password:
         auth = base64.b64encode('%s:%s' % (self.username, self.password)).strip()
         headers['proxy-authorization'] = 'Basic %s' % auth
     for k, v in client.headers.items():
         headers[k.lower()] = v
     headers['connection'] = 'close'
     stream_id = self.spdy_client.open_stream(headers, client)
     stream = self.spdy_client.streams[stream_id]
     stream.request_content_length = int(headers.get('content-length', 0))
     self.spdy_client.poll_stream(stream_id, self.on_frame)
コード例 #2
0
ファイル: http_relay.py プロジェクト: JinGeek/fqsocks
 def do_forward(self, client):
     LOGGER.info('[%s] http relay %s:%s' % (repr(client), self.proxy_ip, self.proxy_port))
     try:
         upstream_sock = client.create_tcp_socket(self.proxy_ip, self.proxy_port, 3)
         if self.is_secured:
             upstream_sock = ssl.wrap_socket(upstream_sock)
             client.add_resource(upstream_sock)
     except:
         if LOGGER.isEnabledFor(logging.DEBUG):
             LOGGER.debug('[%s] http-relay upstream socket connect timed out' % (repr(client)), exc_info=1)
         self.report_failure(client, 'http-relay upstream socket connect timed out')
         return
     upstream_sock.settimeout(3)
     is_payload_complete = recv_and_parse_request(client)
     request_data = '%s %s HTTP/1.1\r\n' % (client.method, client.url)
     client.headers['Connection'] = 'close' # no keep-alive
     request_data += ''.join('%s: %s\r\n' % (k, v) for k, v in client.headers.items())
     if self.username and self.password:
         auth = base64.b64encode('%s:%s' % (self.username, self.password)).strip()
         request_data += 'Proxy-Authorization: Basic %s\r\n' % auth
     request_data += '\r\n'
     if HTTP_TRY_PROXY.http_request_mark:
         upstream_sock.setsockopt(socket.SOL_SOCKET, SO_MARK, HTTP_TRY_PROXY.http_request_mark)
     try:
         upstream_sock.sendall(request_data + client.payload)
     except:
         client.fall_back(reason='send to upstream failed: %s' % sys.exc_info()[1])
     if is_payload_complete:
         response = try_receive_response(client, upstream_sock)
         client.forward_started = True
         client.downstream_sock.sendall(response)
     if HTTP_TRY_PROXY.http_request_mark:
         upstream_sock.setsockopt(socket.SOL_SOCKET, SO_MARK, 0)
     client.forward(upstream_sock)
コード例 #3
0
ファイル: goagent.py プロジェクト: JinGeek/fqsocks
 def do_forward(self, client):
     recv_and_parse_request(client)
     LOGGER.info('[%s] urlfetch %s %s' % (repr(client), client.method, client.url))
     forward(client, self, [p.appid for p in self.proxies if not p.died])
コード例 #4
0
ファイル: goagent.py プロジェクト: alivelee/fqsocks
 def do_forward(self, client):
     recv_and_parse_request(client)
     LOGGER.info('[%s] urlfetch %s %s' % (repr(client), client.method, client.url))
     forward(client, self)