Maintenance of Ruby 2.0.0 ended on February 24, 2016. Read more

In Files

  • webrick/httpproxy.rb




An HTTP Proxy server which proxies GET, HEAD and POST requests.

To create a simple proxy server:

require 'webrick'
require 'webrick/httpproxy'

proxy = Port: 8000

trap 'INT'  do proxy.shutdown end
trap 'TERM' do proxy.shutdown end


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"

proxy = Port: 8000, ProxyContentHandler: handler

Public Class Methods

new(config={}, default=Config::HTTP) click to toggle source

Proxy server configurations. The proxy server handles the following configuration items in addition to those supported by HTTPServer:


Called with a request and response to authorize a request


Appended to the via header


The proxy server’s URI


Called with a request and response and allows modification of the response


Sets the proxy timeouts to 30 seconds for open and 60 seconds for read operations

               # File webrick/httpproxy.rb, line 85
def initialize(config={}, default=Config::HTTP)
  super(config, default)
  c = @config
  @via = "#{c[:HTTPVersion]} #{c[:ServerName]}:#{c[:Port]}"

Commenting is here to help enhance the documentation. For example, code samples, or clarification of the documentation.

If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.

If you wish to post a correction of the docs, please do so, but also file bug report so that it can be corrected for the next release. Thank you.

If you want to help improve the Ruby documentation, please visit