Class: WEBrick::HTTPProxyServer
| Relationships & Source Files | |
| Super Chains via Extension / Inclusion / Inheritance | |
| Class Chain: 
          self,
          HTTPServer,
          GenericServer
         | |
| Instance Chain: 
          self,
          HTTPServer,
          GenericServer
         | |
| Inherits: | WEBrick::HTTPServer 
 | 
| Defined in: | lib/webrick/httpproxy.rb | 
Overview
An HTTP Proxy server which proxies GET, HEAD and POST requests.
To create a simple proxy server:
require 'webrick'
require 'webrick/httpproxy'
proxy = WEBrick::HTTPProxyServer.new Port: 8000
trap 'INT'  do proxy.shutdown end
trap 'TERM' do proxy.shutdown end
proxy.startSee .new for proxy-specific configuration items.
Modifying proxied responses
To modify content the proxy server returns use the :ProxyContentHandler option:
handler = proc do |req, res|
  if res['content-type'] == 'text/plain' then
    res.body << "\nThis content was proxied!\n"
  end
end
proxy =
  WEBrick::HTTPProxyServer.new Port: 8000, ProxyContentHandler: handlerClass Method Summary
- 
    
      .new(config = {}, default = Config::HTTP)  ⇒ HTTPProxyServer 
    
    constructor
    Proxy server configurations. 
HTTPServer - Inherited
| .new | Creates a new HTTP server according to  | 
GenericServer - Inherited
| .new | Creates a new generic server from  | 
Instance Attribute Summary
GenericServer - Inherited
| #config | The server configuration. | 
| #listeners | Sockets listening for connections. | 
| #logger | The server logger. | 
| #status | The server status. | 
| #tokens | Tokens control the number of outstanding clients. | 
Instance Method Summary
HTTPServer - Inherited
| #access_log | Logs  | 
| #do_OPTIONS | The default OPTIONS request handler says GET, HEAD, POST and OPTIONS requests are allowed. | 
| #lookup_server | Finds the appropriate virtual host to handle  | 
| #mount | Mounts  | 
| #mount_proc | Mounts  | 
| #run | Processes requests on  | 
| #search_servlet | Finds a servlet for  | 
| #service | Services  | 
| #umount | Alias for HTTPServer#unmount. | 
| #unmount | Unmounts  | 
| #virtual_host | Adds  | 
GenericServer - Inherited
| #[] | Retrieves  | 
| #run | You must subclass GenericServer and implement #run which accepts a TCP client socket. | 
| #shutdown | Shuts down the server and all listening sockets. | 
| #start | Starts the server and runs the  | 
| #stop | Stops the server from accepting new connections. | 
Constructor Details
    .new(config = {}, default = Config::HTTP)  ⇒ HTTPProxyServer 
  
Proxy server configurations. The proxy server handles the following configuration items in addition to those supported by HTTPServer:
- :ProxyAuthProc
- 
Called with a request and response to authorize a request 
- :ProxyVia
- 
Appended to the via header 
- :ProxyURI
- 
The proxy server's URI 
- :ProxyContentHandler
- 
Called with a request and response and allows modification of the response 
- :ProxyTimeout
- 
Sets the proxy timeouts to 30 seconds for open and 60 seconds for read operations 
# File 'lib/webrick/httpproxy.rb', line 83
def initialize(config={}, default=Config::HTTP) super(config, default) c = @config @via = "#{c[:HTTPVersion]} #{c[:ServerName]}:#{c[:Port]}" end