I’ve written a pretty basic polling proxy web server using Python’s socket module. For the proxy I’ve written a simple readline() using socket’s recv() function.
It goes something like this:
def readline(socket):
buffer = ''
char = socket.recv(1)
while char != '\n' and char != '':
buffer += char
char = socket.recv(1)
if char == '':
buffer = ''
else:
buffer += '\n'
return buffer
From my understanding, if recv() returns an empty string that means there was either a socket error or one side has closed their connection, thus when that happens I return
an empty string to my proxy to let it know the readline() has failed.
When running the proxy, I am able to access sites like youtube.com and yahoo.com, but whenever I try to access http://www.google.com my readline function always returns an empty string
on the very first readline (to read the request line in the HTTP request).
Any ideas?
EDIT:
Sorry I guess I was unclear. I am waiting for the request sent by my Mozilla Firefox client to my proxy server when ‘http://www.google.com/‘ is typed into the address bar and that is where I am hanging. I’m not even getting to the part where I forward the request to the remote server and send back the response.
I think google might be waiting for your request header in first place, if it won’t authorize you it will close connection. And you are not reading requests, you are sending requests. What you read are responses.
But it might be something different then no sent headers.
— UPDATE —
Try to send these headers just after connection.
You can also check what headers your browser is sending to google and what response you get using firebug.