WEBrick HTTPProxyServer question

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

What can I do between the “if” and “end” to throw back
a content to the browser? For example if I have a $cache,
that contains the cached html code:

if $cache.has_key?(req.request_uri)

how to send back here $cache[req.request_uri] asap?

end

Good Afternoon

On Thu, Nov 11, 2010 at 11:06 AM, Nokan E. [email protected]
wrote:

think about a caching proxy, that does not need
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