diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/webrick.rb | 5 | ||||
-rw-r--r-- | lib/webrick/httpproxy.rb | 30 |
2 files changed, 31 insertions, 4 deletions
diff --git a/lib/webrick.rb b/lib/webrick.rb index 842bda21ef..f295e6e7aa 100644 --- a/lib/webrick.rb +++ b/lib/webrick.rb @@ -129,9 +129,8 @@ # # trap 'INT' do proxy.shutdown end # -# Proxies may modifier the content of the response through the -# +:ProxyContentHandler+ callback which will be invoked with the request and -# respone after the remote content has been fetched. +# See WEBrick::HTTPProxy for further details including modifying proxied +# responses. # # == Basic and Digest authentication # diff --git a/lib/webrick/httpproxy.rb b/lib/webrick/httpproxy.rb index 33ce17b2d4..e7226a0a6c 100644 --- a/lib/webrick/httpproxy.rb +++ b/lib/webrick/httpproxy.rb @@ -35,6 +35,34 @@ module WEBrick ## # 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 p.shutdown end + # trap 'TERM' do p.shutdown end + # + # p.start + # + # See ::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: handler class HTTPProxyServer < HTTPServer @@ -46,7 +74,7 @@ module WEBrick # request # :ProxyVia:: Appended to the via header # :ProxyURI:: The proxy server's URI - # :ProxyContentHandler:: Called with a request and resopnse and allows + # :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 |