Class: CookieStore

Inherits:
Object
  • Object
show all
Defined in:
lib/cookie_store.rb,
lib/cookie_store/version.rb

Direct Known Subclasses

HashStore

Defined Under Namespace

Classes: Cookie, CookieParser, HashStore

Constant Summary collapse

4096
MAX_COOKIES_PER_DOMAIN =

Maximum number of cookies per domain (RFC 6265 6.1 requires 50 at least)

50
MAX_COOKIES_TOTAL =

Maximum number of cookies total (RFC 6265 6.1 requires 3000 at least)

3000
VERSION =
'0.2'

Instance Method Summary collapse

Instance Method Details

#close_sessionObject



63
64
65
# File 'lib/cookie_store.rb', line 63

def close_session
  gc(true)
end


31
32
33
# File 'lib/cookie_store.rb', line 31

def cookie_header_for(request_uri)
  cookies_for(request_uri).map(&:to_s).join('; ')
end

#search_domains_for(domain) ⇒ Object

(RFC 2965, section 1)



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/cookie_store.rb', line 36

def search_domains_for(domain)
  domain.downcase!
  serach_domains = []
  
  if domain =~ CookieStore::Cookie::IPADDR
    serach_domains << domain
  else
    domain = domain + '.local' if !(domain =~ /.\../)
    serach_domains << domain
    serach_domains << ".#{domain}"
    
    # H is the host domain name of a host; and,
    # H has the form A.B; and
    if domain =~ /[^\.]+(\..+)/
      reach = $1
      # B has at least one embedded dot
      if reach =~ /.[\.:]./
        # B has at least one embedded dot, or B is the string "local".
        # then the reach of H is .B.
        serach_domains << reach
      end
    end
  end
  
  serach_domains
end

Read and set the cookie from the Set-Cookie header



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/cookie_store.rb', line 17

def set_cookie(request_uri, set_cookie_value)
  request_uri = URI.parse(request_uri)
  
  CookieStore::Cookie.parse_cookies(request_uri, set_cookie_value) do |cookie|
    # reject as per RFC2965 Section 3.3.2
    return if !cookie.request_match?(request_uri) || !(cookie.domain =~ /.+\..+/ || cookie.domain == 'localhost')
  
    # reject cookies over the max-bytes
    return if cookie.to_s.size > MAX_COOKIE_LENGTH
  
    add(cookie)
  end
end