Making a socket connection via a proxy server

Fuzzyman michael at foord.net
Mon Aug 2 06:45:17 EDT 2004


[snip..]

> > 
> > It looks like the Tiny HTTP Proxy (using BaseHTTPServer as it's
> > foundation) intercepts all requests to local addresses and then
> > re-implements the request (whether it is CONNECT, GET, PUT or
> > whatever). It logs everything that goes through it - I will simply
> > edit it to amend the URL that is being asked for.
> 
> Yes, that is exactly what the proxy should do. It relays requests 
> between client and server. However, there is one vital detail you're 
> probably missing that is preventing you from chaining client + proxy*N 
> + server together.
> 
> When sending a HTTP GET request to a server, a client sends a request 
> line containing a URI without a server component. This is because the 
> socket connection to the server is already formed, therefore the 
> server connection details do not need to be repeated. So a standard 
> GET will look like this
> 
> GET /index.html HTTP/1.1
> 
> However, it's different when a client connects to a proxy, because the 
> socket no longer connects directly to the server, but to the proxy 
> instead. The proxy still needs to know to which server it should send 
> the request. So the correct format for sending requests to a proxy is 
> to use the "absoluteURI" form, which includes the server details, e.g.
> 
> GET http://www.python.org:80/index.html HTTP/1.1
> 
> Any proxy that receives such a request now knows that the server to 
> forward to is "www.python.org:80". It will open a connection to 
> www.python.org:80, and send it a GET request for the URI.
> 
> Since you want your proxy to forward to another proxy, i.e. your proxy 
> is a client from your external-access-proxy's point of view, you 
> should also use the absoluteURI form when making requests from your 
> python proxy to your external proxy.

Well the two minor changes you suggested worked straight away for
normal HTML pages - great.
It's not fetching images and a couple of other problems (possibly
because that proxy server can only handle HTTP/1.0 - but I have a more
advanced one called TcpWatch from Zope that I might hack around).

But there's more than enough for me to go on and get it working.

MANY THANKS

Regards,

Fuzzy

http://www.voidspace.org.uk/atlantibots/pythonutils.html



More information about the Python-list mailing list