Class: UU::OS::HTTP::HTTPHeaders

Inherits:
Lang::UniformHash show all
Defined in:
uu_os_connection-2.2.4/lib/uu/os/http/http_headers.rb

Overview

Object representing HTTP headers with Hash-like API.

Instance Method Summary (collapse)

Methods inherited from Lang::UniformHash

#[], #[]=, #default, #delete, #fetch, #has_key?, #has_value?, #include?, #key, #key?, #member?, #merge, #merge!, #replace, #store, #update, #value?, #values_at

Instance Method Details

- (void) add(name, value)

This method returns an undefined value.

Appends value to header of given name.

Parameters:

  • name (Symbol, String)

    Header name.

  • value (String)

    Header value.



24
25
26
27
28
29
30
# File 'uu_os_connection-2.2.4/lib/uu/os/http/http_headers.rb', line 24

def add(name, value)
  if has_key?(name)
    self[name].concat(transform_value(value))
  else
    self[name] = value
  end
end

- (TrueClass, FalseClass) contains(name, value = nil)

Returns true if headers contains header with given name and optional value.

Parameters:

  • name (Symbol, String)

    Header name.

  • value (String) (defaults to: nil)

    Header value snippet (regular expression).

Returns:

  • (TrueClass, FalseClass)

    True if header with given name and optional value snippet exists.



37
38
39
40
41
42
43
44
# File 'uu_os_connection-2.2.4/lib/uu/os/http/http_headers.rb', line 37

def contains(name, value = nil)
  return false if !has_key?(name)
  return true if value.nil?
  self[name].each do |val|
    return true if val =~ /#{value}/
  end
  return false
end