ruby-changes:22375
From: drbrain <ko1@a...>
Date: Fri, 3 Feb 2012 08:17:35 +0900 (JST)
Subject: [ruby-changes:22375] drbrain:r34424 (trunk): * lib/webrick.rb: Moved proxy rewriting to WEBrick::HTTPProxy.
drbrain 2012-02-03 08:17:24 +0900 (Fri, 03 Feb 2012) New Revision: 34424 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=34424 Log: * lib/webrick.rb: Moved proxy rewriting to WEBrick::HTTPProxy. * lib/webrick/httpproxy.rb: Add examples of creating a proxy server and response rewriting using HTTPProxy. Modified files: trunk/ChangeLog trunk/lib/webrick/httpproxy.rb trunk/lib/webrick.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 34423) +++ ChangeLog (revision 34424) @@ -1,3 +1,9 @@ +Fri Feb 3 07:16:47 2012 Eric Hodel <drbrain@s...> + + * lib/webrick.rb: Moved proxy rewriting to WEBrick::HTTPProxy. + * lib/webrick/httpproxy.rb: Add examples of creating a proxy server + and response rewriting using HTTPProxy. + Fri Feb 3 06:53:22 2012 Eric Hodel <drbrain@s...> * ext/openssl/ossl_x509store.c: Add class documentation for Index: lib/webrick.rb =================================================================== --- lib/webrick.rb (revision 34423) +++ lib/webrick.rb (revision 34424) @@ -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 # Index: lib/webrick/httpproxy.rb =================================================================== --- lib/webrick/httpproxy.rb (revision 34423) +++ lib/webrick/httpproxy.rb (revision 34424) @@ -35,6 +35,34 @@ ## # 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 @@ # 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 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/