class HTTP::Request

def __method__(*args)

major version (1.0.0)
The following alias may be removed in two minor versions (0.8.0) or one
def __method__(*args)
  warn "#{Kernel.caller.first}: [DEPRECATION] HTTP::Request#__method__ is deprecated. Use #method instead."
  method(*args)
end

def caching

Returns:
  • (HTTP::Request::Caching) -
def caching
  Caching.new self
end

def default_host

Returns:
  • (String) -
def default_host
  if PORTS[@scheme] == @uri.port
    @uri.host
  else
    "#{@uri.host}:#{@uri.port}"
  end
end

def include_proxy_authorization_header

Compute and add the Proxy-Authorization header
def include_proxy_authorization_header
  digest = Base64.encode64("#{proxy[:proxy_username]}:#{proxy[:proxy_password]}").chomp
  headers["Proxy-Authorization"] = "Basic #{digest}"
end

def initialize(verb, uri, headers = {}, proxy = {}, body = nil, version = "1.1") # rubocop:disable ParameterLists

rubocop:disable ParameterLists
:nodoc:
def initialize(verb, uri, headers = {}, proxy = {}, body = nil, version = "1.1") # rubocop:disable ParameterLists
  @verb   = verb.to_s.downcase.to_sym
  @uri    = uri.is_a?(URI) ? uri : URI(uri.to_s)
  @scheme = @uri.scheme && @uri.scheme.to_s.downcase.to_sym
  fail(UnsupportedMethodError, "unknown method: #{verb}") unless METHODS.include?(@verb)
  fail(UnsupportedSchemeError, "unknown scheme: #{scheme}") unless SCHEMES.include?(@scheme)
  @proxy, @body, @version = proxy, body, version
  @headers = HTTP::Headers.coerce(headers || {})
  @headers["Host"]        ||= default_host
  @headers["User-Agent"]  ||= USER_AGENT
end

def path_for_request_header

def path_for_request_header
  if using_proxy?
    uri
  else
    uri_path_with_query
  end
end

def redirect(uri, verb = @verb)

Returns new Request with updated uri
def redirect(uri, verb = @verb)
  uri = @uri.merge uri.to_s
  req = self.class.new(verb, uri, headers, proxy, body, version)
  req["Host"] = req.uri.host
  req
end

def request_header

Compute HTTP request header for direct or proxy request
def request_header
  "#{verb.to_s.upcase} #{path_for_request_header} HTTP/#{version}"
end

def socket_host

Host for tcp socket
def socket_host
  using_proxy? ? proxy[:proxy_address] : uri.host
end

def socket_port

Port for tcp socket
def socket_port
  using_proxy? ? proxy[:proxy_port] : uri.port
end

def stream(socket)

Stream the request to a socket
def stream(socket)
  include_proxy_authorization_header if using_authenticated_proxy?
  Request::Writer.new(socket, body, headers, request_header).stream
end

def uri_has_query?

def uri_has_query?
  uri.query && !uri.query.empty?
end

def uri_path_with_query

def uri_path_with_query
  path = uri_has_query? ? "#{uri.path}?#{uri.query}" : uri.path
  path.empty? ? "/" : path
end

def using_authenticated_proxy?

Is this request using an authenticated proxy?
def using_authenticated_proxy?
  proxy && proxy.keys.size == 4
end

def using_proxy?

Is this request using a proxy?
def using_proxy?
  proxy && proxy.keys.size >= 2
end