method
proxy_service
v1_8_7_330 -
Show latest stable
-
0 notes -
Class: WEBrick::HTTPProxyServer
- 1_8_6_287 (0)
- 1_8_7_72 (0)
- 1_8_7_330 (0)
- 1_9_1_378 (0)
- 1_9_2_180 (0)
- 1_9_3_125 (0)
- 1_9_3_392 (0)
- 2_1_10
- 2_2_9
- 2_4_6
- 2_5_5
- 2_6_3
- What's this?
proxy_service(req, res)
public
Hide source
# File lib/webrick/httpproxy.rb, line 102 def proxy_service(req, res) # Proxy Authentication proxy_auth(req, res) # Create Request-URI to send to the origin server uri = req.request_uri path = uri.path.dup path << "?" << uri.query if uri.query # Choose header fields to transfer header = Hash.new choose_header(req, header) set_via(header) # select upstream proxy server if proxy = proxy_uri(req, res) proxy_host = proxy.host proxy_port = proxy.port if proxy.userinfo credentials = "Basic " + [proxy.userinfo].pack("m*") credentials.chomp! header['proxy-authorization'] = credentials end end response = nil begin http = Net::HTTP.new(uri.host, uri.port, proxy_host, proxy_port) http.start{ if @config[:ProxyTimeout] ################################## these issues are http.open_timeout = 30 # secs # necessary (maybe bacause http.read_timeout = 60 # secs # Ruby's bug, but why?) ################################## end case req.request_method when "GET" then response = http.get(path, header) when "POST" then response = http.post(path, req.body || "", header) when "HEAD" then response = http.head(path, header) else raise HTTPStatus::MethodNotAllowed, "unsupported method `#{req.request_method}'." end } rescue => err logger.debug("#{err.class}: #{err.message}") raise HTTPStatus::ServiceUnavailable, err.message end # Persistent connction requirements are mysterious for me. # So I will close the connection in every response. res['proxy-connection'] = "close" res['connection'] = "close" # Convert Net::HTTP::HTTPResponse to WEBrick::HTTPProxy res.status = response.code.to_i choose_header(response, res) set_cookie(response, res) set_via(res) res.body = response.body # Process contents if handler = @config[:ProxyContentHandler] handler.call(req, res) end end