By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,929 Members | 1,830 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,929 IT Pros & Developers. It's quick & easy.

Forcing a socket connection via a proxy

P: n/a
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
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.