468,537 Members | 1,827 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,537 developers. It's quick & easy.

Forcing a socket connection via a proxy

I'm trying to create a proxy server - one that will modify requests
made through it.

I've started with Tiny HTTP Proxy by SUZUKI Hisao which is built on
BaseHTTPServer - and I'm starting to get somewhere.

It listens on local ports and tells you whats goign through it.
I'm in a slightly unusual situation though - all internet traffic goes
through a proxy - I have to set the proxy settings to dav-serv:8080 to

What I *want* to do is to point my browser at and have
Tiny Proxy pointed at dav-serv and also modifying requests made
through it. However - when I change my browser proxy settings to, the python code no longer knows that it needs to go via

What I need to do is to force it to use our proxy. Now I know various
protocols allow you to explicitly state the proxy settings... but I'm
struggling to find it.

As far as I can tell Tiny Proxy creates a ProxyHandler with methods
that actually implement the fetches.

For example there are two methods in the ProxyHandler class (which is
a subclass of BaseHTTPServer.BaseHTTPRequestHandler) :
def do_CONNECT(self):
soc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
if self._connect_to(self.path, soc):
self.wfile.write(self.protocol_version +
" 200 Connection established\r\n")
self.wfile.write("Proxy-agent: %s\r\n" %
self._read_write(soc, 300)
print "\t" "bye"

def do_GET(self):
(scm, netloc, path, params, query, fragment) =
self.path, 'http')
if scm != 'http' or fragment or not netloc:
self.send_error(400, "bad url %s" % self.path)
soc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

Which look like they implement GET and CONNECT requests (good at this
aren't I !! - actually I'm way out of my depth). They both get the URL
from self.path and use socket.socket to make connection. I need to get
this connection to be made via a proxy server. (I also want to modify
that URL - but I can handle that myself !!).

Anyone got any pointers for me ?



Jul 18 '05 #1
0 2095

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by b_prikls | last post: by
4 posts views Thread by Fuzzyman | last post: by
7 posts views Thread by Adam Clauss | last post: by
reply views Thread by Marc Bogaard | last post: by
7 posts views Thread by | last post: by
13 posts views Thread by coloradowebdev | last post: by
11 posts views Thread by Jon Mcleod | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.