Module: Nyara::Cookie

Extended by:
Cookie
Included in:
Cookie
Defined in:
lib/nyara/cookie.rb

Overview

rfc6265 (don't look at rfc2109)

Instance Method Summary collapse

Instance Method Details


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/nyara/cookie.rb', line 22

def add_set_cookie header_lines, k, v, expires: nil, max_age: nil, domain: nil, path: nil, secure: nil, httponly: true
  r = "Set-Cookie: "
  if v.nil? or v == true
    r << "#{Ext.escape k.to_s, false}; "
  else
    r << "#{Ext.escape k.to_s, false}=#{Ext.escape v.to_s, false}; "
  end
  r << "Expires=#{expires.to_time.gmtime.rfc2822}; " if expires
  r << "Max-Age=#{max_age.to_i}; " if max_age
  # todo lint rfc1123 §2.1, rfc1034 §3.5
  r << "Domain=#{domain}; " if domain
  r << "Path=#{path}; " if path
  r << "Secure; " if secure
  r << "HttpOnly; " if httponly
  r << "\r\n"
  header_lines << r
end

#decode(header) ⇒ Object

For test


14
15
16
17
18
19
20
# File 'lib/nyara/cookie.rb', line 14

def decode header
  res = ParamHash.new
  if data = header['Cookie']
    ParamHash.parse_cookie res, data
  end
  res
end

#encode(h) ⇒ Object

Encode to string value


7
8
9
10
11
# File 'lib/nyara/cookie.rb', line 7

def encode h
  h.map do |k, v|
    "#{Ext.escape k.to_s, false}=#{Ext.escape v.to_s, false}"
  end.join '; '
end