[prog] Re: [Techtalk] How to write web proxy in Python?

Amanda Babcock alb at quandary.org
Thu Jan 9 17:46:31 EST 2003


On Fri, Jan 10, 2003 at 08:16:18AM +1100, Mary wrote:

> LinuxChix has a programming list, so I've Cc-ed them. 

Oh, I never thought of sending to programming :)  Oops.

> I would suggest using something higher level than sockets if you
> possibly can, unless the assignment requires sockets. 

It's not an assignment.  My university's online instruction system is
awful and is confusing Opera :(  I'm trying to work around that.

> Python has a
> socket module which is easier to use than the C one - it is slightly
> higher level and handles some of the errors itself, so I'd recommend it
> over C, since you've never programmed sockets before.

I actually found the Python socket tutorial, and it looks like pie.
(http://www.amk.ca/python/howto/sockets/)

> If the assignment doesn't require sockets, Python has an httplib module
> that might be appropriate, which will open connections for you without
> you needing to open and use sockets yourself.
> 
> You might even be able to use the urllib module instead, which will
> fetch a url for you with a single line of code.

My goal is for the proxy to be completely transparent except for fixing
the bad Javascript the university is sending me.  It actually seems to
me that using just the sockets would be easier since I can effectively
just let my browser and the university talk to each other, stepping in
only to fix ^M to ^J.  If I just plug sockets into each other, I don't
even need to *know* the URL (just the hostname and port :)

> To make the proxy, I would suggest you look at Python's SimpleHTTPServer
> module, or maybe BaseHTTPServer and override some methods, 

Hmm.  That sounds like more work.

> your replacement (Python's string module will handle the replacement).

Thanks!  I hadn't got around to how to do the replacement yet :)  Good
to know where to find it.

> For a beginning Python programmer, I'd suggest working through the
> tutorial at http://www.python.org/doc/current/tut/tut.html

Cool!

> All modules I've mentioned are documented at
> http://www.python.org/doc/current/modindex.html

Thanks!  I'll let everybody know how it goes.

Amanda



More information about the Programming mailing list