Class: Ritm::Proxy::ProxyServer
- Inherits:
-
WEBrick::HTTPProxyServer
- Object
- WEBrick::HTTPProxyServer
- Ritm::Proxy::ProxyServer
- Includes:
- InterceptUtils
- Defined in:
- lib/ritm/proxy/proxy_server.rb
Overview
Proxy server that accepts request and response intercept handlers for HTTP traffic HTTPS traffic is redirected to the SSLReverseProxy for interception
Instance Method Summary collapse
-
#do_CONNECT(req, res) ⇒ Object
Override Patches the destination address on HTTPS connections to go via the HTTPS Reverse Proxy.
-
#proxy_service(req, res) ⇒ Object
Override Handles HTTP (no SSL) traffic interception.
-
#proxy_uri(req, _res) ⇒ Object
Override.
- #start_async ⇒ Object
Methods included from InterceptUtils
#intercept_request, #intercept_response
Instance Method Details
#do_CONNECT(req, res) ⇒ Object
Override Patches the destination address on HTTPS connections to go via the HTTPS Reverse Proxy
21 22 23 24 |
# File 'lib/ritm/proxy/proxy_server.rb', line 21 def do_CONNECT(req, res) req.unparsed_uri = @config[:https_forward] unless ssl_pass_through? req.unparsed_uri super end |
#proxy_service(req, res) ⇒ Object
Override Handles HTTP (no SSL) traffic interception
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/ritm/proxy/proxy_server.rb', line 28 def proxy_service(req, res) # Proxy Authentication proxy_auth(req, res) # Request modifier handler intercept_request(@config[:request_interceptor], req, @config[:ritm_conf].intercept.request) begin send("do_#{req.request_method}", req, res) rescue NoMethodError raise WEBrick::HTTPStatus::MethodNotAllowed, "unsupported method `#{req.request_method}'." rescue StandardError => err raise WEBrick::HTTPStatus::ServiceUnavailable, err. end # Response modifier handler intercept_response(@config[:response_interceptor], req, res, @config[:ritm_conf].intercept.response) end |
#proxy_uri(req, _res) ⇒ Object
Override
48 49 50 51 52 53 54 55 56 |
# File 'lib/ritm/proxy/proxy_server.rb', line 48 def proxy_uri(req, _res) if req.request_method == 'CONNECT' # Let the reverse proxy handle upstream proxies for https nil else proxy = @config[:ritm_conf].misc.upstream_proxy proxy.nil? ? nil : URI.parse(proxy) end end |
#start_async ⇒ Object
13 14 15 16 17 |
# File 'lib/ritm/proxy/proxy_server.rb', line 13 def start_async trap(:TERM) { shutdown } trap(:INT) { shutdown } Thread.new { start } end |