In Files
- webrick/httpproxy.rb
Parent
HTTPServer
Methods
Class/Module Index
- 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
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)
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 84 def initialize(config={}, default=Config::HTTP) super(config, default) c = @config @via = "#{c[:HTTPVersion]} #{c[:ServerName]}:#{c[:Port]}" end