WEBrick HTTPProxyServer question

N

Nokan Emiro

[Note: parts of this message were removed to make it a legal post.]

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
 
J

John W Higgins

[Note: parts of this message were removed to make it a legal post.]

Good Afternoon

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,736
Latest member
zacharyharris

Latest Threads

Top