Class: Typhoeus::Response::Header Private

Inherits:
Hash
  • Object
show all
Defined in:
lib/typhoeus/response/header.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

This class represents the response header. It can be accessed like a hash. Values can be strings (normal case) or arrays of strings (for duplicates headers)

Since:

  • 0.5.0

API:

  • private

Instance Method Summary collapse

Constructor Details

#initialize(raw) ⇒ Header

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Create a new header.

Examples:

Create new header.

Header.new(raw)

Parameters:

  • The raw header.

Since:

  • 0.5.0

API:

  • private



19
20
21
22
23
24
# File 'lib/typhoeus/response/header.rb', line 19

def initialize(raw)
  super({})
  @raw = raw
  @sanitized = {}
  parse
end

Instance Method Details

#[](key) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 0.5.0

API:

  • private



26
27
28
# File 'lib/typhoeus/response/header.rb', line 26

def [](key)
  fetch(key) { @sanitized[key.to_s.downcase] }
end

#parseObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parses the raw header.

Examples:

Parse header.

header.parse

Since:

  • 0.5.0

API:

  • private



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/typhoeus/response/header.rb', line 34

def parse
  case @raw
  when Hash
    raw.each do |k, v|
      process_pair(k, v)
    end
  when String
    raw.split(/\r?\n(?!\s)/).each do |header|
      header.strip!
      next if header.empty? || header.start_with?( 'HTTP/' )
      process_line(header)
    end
  end
end