public Method

HTTPProxyServer.proxy_service(req, res)

There's no documentation for this item.

Source Code

# File 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
Comments

Have your say
Please use Textile formatting (click here for a cheat sheet). Use <code/> and <pre/> for code samples.
Click here to login with OpenID to to post comments.