Making a socket connection via a proxy server

Fuzzyman michael at foord.net
Mon Aug 2 02:43:59 EDT 2004


[snip..]

> 
> > It looks like the CONNECT and GET requests are just implemented using
> > simple socket commands. (I say simple because there isn't a lot of
> > code - I'm not familiar with the actual behaviour of sockets, but it
> > doesn't look too complicated).
> > 
> > What I need to do is rewrite the soc.connect(host_port) line in the
> > following example so that it connects *via* my proxy-server. (which it
> > doesn't by default).
> > 
> > I think the current format of host_port is a tuple : (host_domain,
> > port_no)
> > 
> > Below is a summary of the GET command (I've inlined all the method
> > calls - this example starts from the do_GET method) :
> > 
> > soc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
> > soc.connect(host_port)
> 
> What is the value of host_port at this point? It *should* be the 
> address of your external access proxy, i.e. dav-serv:8080
> 
> > soc.send("%s %s %s\r\n" % (
> >     self.command,
> >     urlparse.urlunparse(('', '', path, params, query, '')),
> >     self.request_version))
> 
> And you're not sending an absoluteURI: this should be amended to 
> contain the server details of the the server that is finally going to 
> service the request. For the python.org example above, this code would be
> 
> soc.send("%s %s %s\r\n" % (
>      self.command,
>      urlparse.urlunparse(('http', 'www.python.org:80', path, params, 
> query, '')),
>      self.request_version))
> 
> though of course, these values should be made available to you by 
> TinyHTTPProxy. Taking a brief look at the code, these values should 
> available through the variables "scm" and "netloc". So your outgoing 
> connection code from TinyHTTPProxy should look something like this
> 
> soc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
> soc.connect( ('dav-serv', 8080) )
> soc.send("%s %s %s\r\n" % (
>      self.command,
>      urlparse.urlunparse((scm, netloc, path, params, query, '')),
>      self.request_version))
> 
> HTH,


Thanks to all of you who replied.
I think I uderstand enough to have a go - I need to make the
connection to the proxy and the request for the absolute URI. That at
least gives me something to go at and it shouldn't be too hard.

Many Thanks for your help.

Fuzzyman

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



More information about the Python-list mailing list