Class: HttpHeaders

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

Overview

Class HttpHeaders parses a http header_str from Curl::Easy into component parts.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(str) ⇒ HttpHeaders

Returns a new instance of HttpHeaders.



6
7
8
# File 'lib/http_headers.rb', line 6

def initialize(str)
  @content = str.split(/\\r\\n|\n|\r/)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args) ⇒ Object



18
19
20
# File 'lib/http_headers.rb', line 18

def method_missing(sym, *args)
  detect_multi_value_keys(sym)
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



4
5
6
# File 'lib/http_headers.rb', line 4

def content
  @content
end

Instance Method Details

#response_codeObject



14
15
16
# File 'lib/http_headers.rb', line 14

def response_code
  @content[0].match(/HTTP\/\d\.\d (\d{3}.*)/)[1]
end

#versionObject



10
11
12
# File 'lib/http_headers.rb', line 10

def version
  @content[0].match(/HTTP\/\d\.\d/)[0]
end