Class: Adelnor::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/adelnor/request.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message) ⇒ Request

Returns a new instance of Request.



8
9
10
11
12
13
14
# File 'lib/adelnor/request.rb', line 8

def initialize(message)
  @message = message
  @request_method = @request_path = nil

  @headers = {}
  @body    = ''
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



5
6
7
# File 'lib/adelnor/request.rb', line 5

def body
  @body
end

#content_lengthObject (readonly)

Returns the value of attribute content_length.



5
6
7
# File 'lib/adelnor/request.rb', line 5

def content_length
  @content_length
end

#headersObject (readonly)

Returns the value of attribute headers.



5
6
7
# File 'lib/adelnor/request.rb', line 5

def headers
  @headers
end

#path_infoObject (readonly)

Returns the value of attribute path_info.



5
6
7
# File 'lib/adelnor/request.rb', line 5

def path_info
  @path_info
end

#query_stringObject (readonly)

Returns the value of attribute query_string.



5
6
7
# File 'lib/adelnor/request.rb', line 5

def query_string
  @query_string
end

#request_methodObject (readonly)

Returns the value of attribute request_method.



5
6
7
# File 'lib/adelnor/request.rb', line 5

def request_method
  @request_method
end

#request_pathObject (readonly)

Returns the value of attribute request_path.



5
6
7
# File 'lib/adelnor/request.rb', line 5

def request_path
  @request_path
end

Class Method Details

.build(*args) ⇒ Object



16
17
18
# File 'lib/adelnor/request.rb', line 16

def self.build(*args)
  new(*args).build
end

Instance Method Details

#buildObject



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/adelnor/request.rb', line 20

def build
  lines    = @message.split(/\r\n/)
  headline = lines.shift

  return self unless headline

  parse_headline!(headline)
  parse_headers!(lines)

  self
end

#parse_body!(client) ⇒ Object



32
33
34
35
36
37
# File 'lib/adelnor/request.rb', line 32

def parse_body!(client)
  @content_length = @headers['Content-Length']
  return unless @content_length

  @body = client.read(@content_length.to_i)
end