Class: Minver::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/minver/parser.rb

Instance Method Summary collapse

Constructor Details

#initialize(stream_or_string) ⇒ Parser

Returns a new instance of Parser.



5
6
7
8
9
10
11
# File 'lib/minver/parser.rb', line 5

def initialize(stream_or_string)
  @stream = if stream_or_string.is_a? String
    StringIO.new(stream_or_string)
  else
    stream_or_string
  end
end

Instance Method Details

#[](key) ⇒ Object



27
28
29
# File 'lib/minver/parser.rb', line 27

def [](key)
  headers[key]
end

#bodyObject



35
36
37
# File 'lib/minver/parser.rb', line 35

def body
  @body ||= @stream.read(headers["Content-Length"].to_i)
end

#dataObject



31
32
33
# File 'lib/minver/parser.rb', line 31

def data
  @data ||= [*head, body].join
end

#headersObject



21
22
23
24
25
# File 'lib/minver/parser.rb', line 21

def headers
  @headers ||= header_lines.inject({}) do |h, line|
    h.merge(Hash[[line.rstrip.split(': ', 2)]])
  end
end

#http_methodObject



13
14
15
# File 'lib/minver/parser.rb', line 13

def http_method
  @http_method ||= request_match[1]
end

#pathObject



39
40
41
# File 'lib/minver/parser.rb', line 39

def path
  @path ||= request_uri.first
end

#query_stringObject



43
44
45
# File 'lib/minver/parser.rb', line 43

def query_string
  @query_string ||= request_uri[1] || ''
end

#request_http_versionObject



17
18
19
# File 'lib/minver/parser.rb', line 17

def request_http_version
  @request_http_version ||= request_match[3]
end