On 08.10.2007 18:29, kazaam wrote:
>> It seems you are trying to write a HTTP proxy. If it is not for the
>> educational experience then I suggest to look into the RAA or in the
>> standard lib. I believe a proxy class is part of Webrick.
>
> Thanks for these hints!! I didn't new about RAA which seems like a really great collection. And you have also been right with webrick which makes it pretty easy to do an http-proxy:
>
> #!/usr/bin/env ruby
> $Verbose=true
The variable is called $VERBOSE.
> require "webrick"
> require "webrick/httpproxy"
>
> pch = Proc.new{|req, res|
> p [ req.request_line, res.status_line ]
> }
>
> def upstream_proxy
> if prx = ENV["http_proxy"]
> return URI.parse(prx)
> end
> return nil
> end
You can simplify that to
def upstream_proxy
prx = ENV["http_proxy"] and URI.parse(prx)
end
> httpd = WEBrick::HTTPProxyServer.new(
> :Port => 10080,
> :ProxyContentHandler => pch,
> :ProxyURI => upstream_proxy
> )
> Signal.trap(:INT){ httpd.shutdown }
> httpd.start
:-)
Kind regards
robert