class HTTP::Request

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.to_s.downcase.to_sym if @uri.scheme
  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']        ||= @uri.host
  @headers['User-Agent']  ||= "RubyHTTPGem/#{HTTP::VERSION}"
end

def method(*args)

major version (1.0.0)
The following method may be removed in two minor versions (0.7.0) or one
def method(*args)
  warn "#{Kernel.caller.first}: [DEPRECATION] HTTP::Request#method is deprecated. Use #verb instead. For Object#method, use #__method__."
  @verb
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
  if using_proxy?
    "#{verb.to_s.upcase} #{uri} HTTP/#{version}"
  else
    path = uri.query && !uri.query.empty? ? "#{uri.path}?#{uri.query}" : uri.path
    path = '/' if path.empty?
    "#{verb.to_s.upcase} #{path} HTTP/#{version}"
  end
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 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