summaryrefslogtreecommitdiff
path: root/lib/webrick/httpproxy.rb
diff options
context:
space:
mode:
authordrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-02-02 23:17:24 +0000
committerdrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-02-02 23:17:24 +0000
commit42ffb2ed151814c2f53f0316b8bee2f4ab6966b8 (patch)
tree6af93ac6ad811dc2875dfc9e5a5e97a7510e3edd /lib/webrick/httpproxy.rb
parent30f0e97ef08e1518069c36b861d9d6a6ea4035e3 (diff)
* 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34424 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/webrick/httpproxy.rb')
-rw-r--r--lib/webrick/httpproxy.rb30
1 files changed, 29 insertions, 1 deletions
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