Class: WEBrick::HTTPProxyServer (Ruby 2.3.2)
Description: Class : WEBrick::HTTPProxyServer - Ruby 2.3.2

- Home
- Core 2.3.2
- Std-lib 2.3.2
- Downloads

Support for the Ruby 2.3 series has ended. See here for reference.

### Home Classes Methods

### In Files

- webrick/httpproxy.rb

### Parent

HTTPServer

### Methods

- ::new

### Class/Module Index

Quicksearch

- Dir
- Errno
- Errno::ECONNABORTED
- Errno::ECONNRESET
- Errno::EPROTO
- File
- Object
- WEBrick
- WEBrick::AccessLog
- WEBrick::AccessLog::AccessLogError
- WEBrick::BasicLog
- WEBrick::CGI
- WEBrick::Config
- WEBrick::Config::OpenSSL
- WEBrick::Cookie
- WEBrick::Daemon
- WEBrick::GenericServer
- WEBrick::HTMLUtils
- WEBrick::HTTPAuth
- WEBrick::HTTPAuth::Authenticator
- WEBrick::HTTPAuth::BasicAuth
- WEBrick::HTTPAuth::DigestAuth
- WEBrick::HTTPAuth::Htdigest
- WEBrick::HTTPAuth::Htgroup
- WEBrick::HTTPAuth::Htpasswd
- WEBrick::HTTPAuth::ProxyAuthenticator
- WEBrick::HTTPAuth::ProxyBasicAuth
- WEBrick::HTTPAuth::ProxyDigestAuth
- WEBrick::HTTPAuth::UserDB
- WEBrick::HTTPProxyServer
- WEBrick::HTTPRequest
- WEBrick::HTTPResponse
- WEBrick::HTTPServer
- WEBrick::HTTPServerError
- WEBrick::HTTPServlet
- WEBrick::HTTPServlet::AbstractServlet
- WEBrick::HTTPServlet::CGIHandler
- WEBrick::HTTPServlet::DefaultFileHandler
- WEBrick::HTTPServlet::ERBHandler
- WEBrick::HTTPServlet::FileHandler
- WEBrick::HTTPServlet::HTTPServletError
- WEBrick::HTTPServlet::ProcHandler
- WEBrick::HTTPStatus
- WEBrick::HTTPStatus::ClientError
- WEBrick::HTTPStatus::EOFError
- WEBrick::HTTPStatus::Error
- WEBrick::HTTPStatus::Info
- WEBrick::HTTPStatus::Redirect
- WEBrick::HTTPStatus::ServerError
- WEBrick::HTTPStatus::Status
- WEBrick::HTTPStatus::Success
- WEBrick::HTTPUtils
- WEBrick::HTTPUtils::FormData
- WEBrick::HTTPVersion
- WEBrick::Log
- WEBrick::ServerError
- WEBrick::SimpleServer
- WEBrick::Utils
- WEBrick::Utils::TimeoutHandler
- WEBrick::Utils::TimeoutHandler::Thread

No matching classes.

# WEBrick::HTTPProxyServer

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.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

### 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:

: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 webrick/httpproxy.rb, line 83
    def initialize(config={}, default=Config::HTTP)
      super(config, default)
      c = @config
      @via = "#{c[:HTTPVersion]} #{c[:ServerName]}:#{c[:Port]}"
    end