Module: WebAgent::CookieUtils

Included in:
Cookie, CookieManager
Defined in:
lib/httpclient/webagent-cookie.rb

Instance Method Summary collapse

Instance Method Details

#domain_match(host, domain) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/httpclient/webagent-cookie.rb', line 34

def domain_match(host, domain)
  return false if domain.nil?
  domainname = domain.sub(/\.\z/, '').downcase
  hostname = host.sub(/\.\z/, '').downcase
  case domain
  when /\d+\.\d+\.\d+\.\d+/
    return (hostname == domainname)
  when '.'
    return true
  when /^\./
    # allows; host == rubyforge.org, domain == .rubyforge.org
    return tail_match?(domainname, '.' + hostname)
  else
    return (hostname == domainname)
  end
end

#head_match?(str1, str2) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/httpclient/webagent-cookie.rb', line 22

def head_match?(str1, str2)
  str1 == str2[0, str1.length]
end

#tail_match?(str1, str2) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
29
30
31
32
# File 'lib/httpclient/webagent-cookie.rb', line 26

def tail_match?(str1, str2)
  if str1.length > 0
    str1 == str2[-str1.length..-1].to_s
  else
    true
  end
end