Class: HTTParty::CookieHash

Inherits:
Hash
  • Object
show all
Defined in:
lib/httparty/cookie_hash.rb

Overview

:nodoc:

Constant Summary collapse

CLIENT_COOKIES =
%w(path expires domain path secure httponly samesite)

Instance Method Summary collapse

Instance Method Details

#add_cookies(data) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/httparty/cookie_hash.rb', line 6

def add_cookies(data)
  case data
  when Hash
    merge!(data)
  when String
    data.split('; ').each do |cookie|
      key, value = cookie.split('=', 2)
      self[key.to_sym] = value if key
    end
  else
    raise "add_cookies only takes a Hash or a String"
  end
end


20
21
22
# File 'lib/httparty/cookie_hash.rb', line 20

def to_cookie_string
  select { |k, v| !CLIENT_COOKIES.include?(k.to_s.downcase) }.collect { |k, v| "#{k}=#{v}" }.join('; ')
end