RAA - reverse_proxy

reverse_proxy / 1.0

Short description: WEBrick::HTTPReverseProxyServer class
Category: Library/WWW
Status: beta
Created: 2006-08-01 15:13:05 GMT
Last update: 2006-08-01 15:13:05 GMT
Owner: Richard Kernahan (Projects of this owner)
Homepage: http://rubyforge.org/snippet/detail.php?type=snippet&id=117
Download: http://rubyforge.org/snippet/detail.php?type=snippet&id=117
License: Artistic
Dependency:
None
Description:
HTTP Reverse proxy server
Use case: you have several services running as different users for security purposes (they might even be chrooted).
In production we use apache but for testing I prefer to use webrick because I find it more flexible for unit testing.
The proxy mapping is modelled on the ProxyPass directive of apache. For example:

original URL              proxies  private URL
------------------------    ==>   --------------------------
/marmalade/index.html             localhost:8081/index.html
/apps/vegemite?id=123             localhost:8082/apps/someservlet?id=123
 
Its not designed to be mod_rewrite (eg. query_string cannot be transformed), but you can specify proxy rules that match
a fragment of the original URL and replace it with something else while also sending the new URL to the proxied host and port. 
So the rules in that example are specified thus:
 
  serverConfig = {
    :Port => 80,
    :ProxyRules => [ 
       ProxyRule.new('^/marmalade/', 'localhost', 8081, '/'),
       ProxyRule.new('vegemite', 'localhost', 8082, 'someservlet')
    ]
  }
  server = WEBrick::HTTPReverseProxyServer.new(serverConfig)
 
ProxyRules is an array so the order is important - the first match is used! If no matches are found then the URL is 
handled by the local web server normally.

Edit this project (for project owner)

back to RAA top