Class: Iconoclasm::Headers

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

Constant Summary collapse

REGEXP =
/^\s*HTTP\/(\d\.\d)\s*(\d{3})\s*(.*)\s*$/i

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(string) ⇒ Headers

Returns a new instance of Headers.



7
8
9
10
11
12
# File 'lib/iconoclasm/headers.rb', line 7

def initialize(string)
  header_string = string.dup
  http_response = header_string.slice!(REGEXP)
  @version, @code, @message = parse_http_response(http_response)
  @header_hash              = parse_header_string(header_string.strip)
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



5
6
7
# File 'lib/iconoclasm/headers.rb', line 5

def code
  @code
end

#messageObject (readonly)

Returns the value of attribute message.



5
6
7
# File 'lib/iconoclasm/headers.rb', line 5

def message
  @message
end

#versionObject (readonly)

Returns the value of attribute version.



5
6
7
# File 'lib/iconoclasm/headers.rb', line 5

def version
  @version
end

Instance Method Details

#[](header) ⇒ Object



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

def [](header)
  @header_hash[convert_header_key(header.to_s)]
end

#content_lengthObject Also known as: length



23
24
25
# File 'lib/iconoclasm/headers.rb', line 23

def content_length
  @content_length ||= self['content_length']
end

#content_typeObject Also known as: type



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

def content_type
  @content_type ||= self['content_type']
end

#locationObject



28
29
30
# File 'lib/iconoclasm/headers.rb', line 28

def location
  @location ||= self['location']
end