Updated 2012-10-28 21:46:56 by RLE

[Explain notion of proxy.] RS: In general, a proxy is someone or something that stands for someone or something else. Specifically, a proxy host can be a firewall that routes web traffic from and to other sites (see autoproxy).

Proxomitron's[1] said to be handy under Windows, and knows SSL. (MAKR 2009-04-09 as of today the Proxomitron link points to a page that says that this domain is for sale.)

LES: Proxomitron is very nice, but really bugged me for using its own regex dialect, which I never got to memorize. Privoxy [2] doesn't look as fancy, but works very well and sticks to good old PCRE. Oh, yes, and it runs on several platforms.

LES on 2005-10-07: I would like to make a proxy to filter Web content, like Privoxy. But I have no idea of how to make it listen on a given port and get the browser's request. Fectching pages is easy, but I have no idea of how to send it back to the browser. Can someone give me a few rough pointers on these two things (listening on a port and sending data to the browser)?

MG I'm not sure how to do the actual proxy code, but listening on a port and sending data back is actually pretty easy. It's all just done with socket, puts, and gets (and probably a fileevent too). To listen on a port, you just need to start a server with
  set port 1234
  # Start listening on port $port for connections. When we get one, [myCmd] will be run
  set sock [socket -socket myCmd $port]
  
  proc myCmd {channel cAddr cPort} {
    puts "New connection from ${cAddr}:$cPort (socket $channel)"
    # set up a fileevent, so that when we have data to read from the client, we do so
    fileevent $channel readable [list doSomeStuff $channel]
  };# myCmd
  
  proc doSomeStuff {channel} {
    # read data, and return if there's an error, or the channel is closed
    if { [catch {gets $channel line}] || [eof $channel] } {
         close $channel
         return;
       }
    # do some interesting stuff with $line, which we received from the client
    set result [foobar $line]
    if { $result == "1" } {
         # send message back to client, but don't close the channel. This means they can send more data.
         puts $channel "We got $line. Send more"
       } else {
         # Send message back, then close the channel.
         puts $channel "We got $line. That is all"
         close $channel
       }
  };# doSomeStuff

There's a slightly longer example at Port Forwarding in Pure-Tcl, which also listens on a port for connections like this. My apologies for any typos in that code, btw, it's 5:30 am ;)

LES: It works very well. Thank you again.

AH 2005-07-10: Tcl nano proxy server is one possible place to start.

MAKR 2009-04-09: aspect mentioned another proxy written in Tcl in the chat today. It is called Loxy: Logging HTTP Proxy and can be found here: http://www.parand.com/projects/loxy/.