I'm making a proxy for my project and I'm trying to send to the browser (Firefox) an HTTP header to continue the "Conversation" between me(Proxy server) and the browser. The issue is: when I'm refreshing any page, the page Keeping loading. I use socket and select for the proxy:
import socket, select
#Sending a message for the waiting list
def send_Waiting_Messages(wlist):
for msg in messages_to_send:
clientSocket, data = msg
if clientSocket in wlist:
clientSocket.send('HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n')
messages_to_send.remove(msg)
serverSocket = socket.socket()
serverSocket.bind(('0.0.0.0',8080))
serverSocket.listen(10)
open_client_sockets = []
messages_to_send = []
while True:
rlist, wlist, xlist = select.select([serverSocket] + open_client_sockets, open_client_sockets, [])
for currentSocket in rlist:
if currentSocket is serverSocket:
newSocket, addr = serverSocket.accept()
open_client_sockets.append(newSocket)
else:
data = currentSocket.recv(1024)
if data == "":
open_client_sockets.remove(currentSocket)
print 'Conn is closed'
else:
print data
messages_to_send.append((currentSocket, 'Hello, ' + data))
send_Waiting_Messages(wlist)
These lines:
clientSocket.send('HTTP/1.1 200 OK\r\n')
clientSocket.send('Content-Type: text/html\r\n\r\n')
are for sending the header.
Thanks for helpers!!