Module: QNA::RequestInfoMethods

Included in:
Request
Defined in:
lib/qna/request_info.rb

Instance Method Summary collapse

Instance Method Details

#connectionObject



12
13
14
# File 'lib/qna/request_info.rb', line 12

def connection
  @headers['connection']
end

#forwarded_forObject



61
62
63
# File 'lib/qna/request_info.rb', line 61

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

#hostObject



8
9
10
# File 'lib/qna/request_info.rb', line 8

def host
  @headers['host']
end

#methodObject



24
25
26
# File 'lib/qna/request_info.rb', line 24

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

#pathObject



36
37
38
# File 'lib/qna/request_info.rb', line 36

def path
  @path ||= uri.path
end

#protocolObject



20
21
22
# File 'lib/qna/request_info.rb', line 20

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

#queryObject



44
45
46
47
48
# File 'lib/qna/request_info.rb', line 44

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

#query_stringObject



40
41
42
# File 'lib/qna/request_info.rb', line 40

def query_string
  @query_string ||= uri.query
end

#request_idObject



57
58
59
# File 'lib/qna/request_info.rb', line 57

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

#schemeObject



28
29
30
# File 'lib/qna/request_info.rb', line 28

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

#split_query_string(query) ⇒ Object



50
51
52
53
54
55
# File 'lib/qna/request_info.rb', line 50

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

#upgrade_protocolObject



16
17
18
# File 'lib/qna/request_info.rb', line 16

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

#uriObject



32
33
34
# File 'lib/qna/request_info.rb', line 32

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