module Qeweney::RequestInfoMethods

def accept_encoding

into account q weights)
TODO: should return encodings in client's order of preference (and take
def accept_encoding
  encoding = @headers['accept-encoding']
  return [] unless encoding
  encoding.split(',').map { |i| i.strip }
end

def connection

def connection
  @headers['connection']
end

def forwarded_for

def forwarded_for
  @headers['x-forwarded-for']
end

def host

def host
  @headers['host']
end

def method

def method
  @method ||= @headers[':method'].downcase
end

def path

def path
  @path ||= uri.path
end

def protocol

def protocol
  @protocol ||= @adapter.protocol
end

def query

def query
  return @query if @query
  
  @query = (q = uri.query) ? split_query_string(q) : {}
end

def query_string

def query_string
  @query_string ||= uri.query
end

def request_id

def request_id
  @headers['x-request-id']
end

def scheme

def scheme
  @scheme ||= @headers[':scheme']
end

def split_query_string(query)

def split_query_string(query)
  query.split('&').each_with_object({}) do |kv, h|
    k, v = kv.split('=')
    h[k.to_sym] = URI.decode_www_form_component(v)
  end
end

def upgrade_protocol

def upgrade_protocol
  connection == 'upgrade' && @headers['upgrade']&.downcase
end

def uri

def uri
  @uri ||= URI.parse(@headers[':path'] || '')
end

def websocket_version

def websocket_version
  headers['sec-websocket-version'].to_i
end