From: John W Higgins Date: 2010-11-12T08:14:05+09:00 Subject: Re: WEBrick HTTPProxyServer question --000e0cd47c482fadda0494cf21be Content-Type: text/plain; charset=ISO-8859-1 Good Afternoon On Thu, Nov 11, 2010 at 11:06 AM, Nokan Emiro wrote: > Hi, > > could somebody please show me what can I do > to prevent WEBrick::HTTPProxyServer from > accessing the webserver on special cases? There > are cases when the proxy already knows in the > RequestCallback procedure that the content on > the webserver is irrelevant to the data sent back > to the browser. Think about a http proxy, that > has a list of URLs that should be blocked, or > think about a caching proxy, that does not need > to contact the webserver if the content is already > available in the RequestCallback phase: > > require 'webrick/httpproxy' > server = WEBrick::HTTPProxyServer.new( > :Port => 8080, > :RequestCallback => Proc.new do |req, res| > if ## condition ## > ## what to do here to prevent http req? ## > end > end > ) > server.start > > First, it appears that RequestCallback merely allows for the modification of the initial request, so you could modify the request to point to a cache server and have it serve the initial request if you wanted. The other option is to subclass the HTTPProxyServer class and do what you want from within. Quick and dirty concept require 'webrick/httpproxy' class X < WEBrick::HTTPProxyServer def do_GET(req, res) #there are also do_POST and friends that you might want to override as well if req.request_uri = 'blah blah blah' #do whatever you want here #you will need to setup the res response object to properly look like an HTTP Response else super end end end server = X.new( :Port => 8080 ) server.start John --000e0cd47c482fadda0494cf21be--