Class: Opensaz::HTTPRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/opensaz/http_request.rb

Direct Known Subclasses

HTTPResponse

Constant Summary collapse

CRLF =
"\r\n"
SEPERATOR =
": "

Instance Method Summary collapse

Constructor Details

#initialize(content) ⇒ HTTPRequest

Returns a new instance of HTTPRequest.



7
8
9
10
# File 'lib/opensaz/http_request.rb', line 7

def initialize(content)
  raise "request_str couldn't be nil" if content == nil
  @content = content
end

Instance Method Details

#bodyObject



18
19
20
21
# File 'lib/opensaz/http_request.rb', line 18

def body
  str = @content.split(CRLF * 2)[1..-1].join(CRLF * 2)
  str == "" ? nil : str
end

#headersObject



12
13
14
15
16
# File 'lib/opensaz/http_request.rb', line 12

def headers
  first_line = headers_str.split(CRLF)[0]
  following_lines = headers_str.split(CRLF)[1..-1]
  get_request_line(first_line).merge(get_headers(following_lines))
end