Python - HTTPS隧道 - 连接方法

时间:2016-10-30 12:46:38

标签: python http proxy connect tunnel

我正在尝试在python中创建代理。我首先实现了CONNECT方法。

我发送:

HTTP/1.1 200 Connection Established\r\nProxy-Agent: Pyroxy\r\nConnection: close\r\n\r\n

但是,即使我将上面指定的字符串发送给它,客户端也不会响应。

我的代码是:

def HandleConnectMethod(self, clientSocket, forwarderSocket, pHeaders):
connectAddress = pHeaders['Headers']['Host']

print 'Handling connect request to %s' % connectAddress

if ':' in connectAddress:
    host, port = connectAddress.split(':')
    forwarderSocket.connect((host, int(port)))
else:
    forwarderSocket.connect((connectAddress, 80))

print 'Connection established to %s' % connectAddress

clientSocket.send('HTTP/1.1 200 Connection Established\r\nProxy-Agent: Pyroxy\r\nConnection: close\r\n\r\n')
Thread(target=self.HandleForwarderThread, args=[forwarderSocket, clientSocket]).start()

0 个答案:

没有答案