我正在尝试在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()