class Typhoeus::Response::Header
@api private
Values can be strings (normal case) or arrays of strings (for duplicates headers)
It can be accessed like a hash.
This class represents the response header.
def [](key)
def [](key) fetch(key) { @sanitized[key.to_s.downcase] } end
def initialize(raw)
-
raw
(String
) -- The raw header.
Other tags:
- Example: Create new header. -
def initialize(raw) super({}) @raw = raw @sanitized = {} parse end
def parse
- Example: Parse header. -
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
def process_line(header)
-
(void)
-
def process_line(header) key, value = header.split(':', 2) process_pair(key.strip, (value ? value.strip.gsub(/\r?\n\s*/, ' ') : '')) end
def process_pair(key, value)
-
(void)
-
def process_pair(key, value) set_value(key, value, self) @sanitized[key.downcase] = self[key] end
def raw
-
(String)
- The raw header.
Other tags:
- Example: Return raw header. -
def raw @raw || '' end
def set_default_proc_on(hash, default_proc)
-
(void)
-
def set_default_proc_on(hash, default_proc) if hash.respond_to?(:default_proc=) hash.default_proc = default_proc else hash.replace(Hash.new(&default_proc).merge(hash)) end end
def set_value(key, value, hash)
-
(void)
-
def set_value(key, value, hash) current_value = hash[key] if current_value if current_value.is_a? Array current_value << value else hash[key] = [current_value, value] end else hash[key] = value end end