/lib/httparty/cookie_hash.rb
http://github.com/jnunemaker/httparty · Ruby · 21 lines · 19 code · 2 blank · 0 comment · 1 complexity · f3f9227b2a586ceb78f03135f1ea93df MD5 · raw file
- class HTTParty::CookieHash < Hash #:nodoc:
- CLIENT_COOKIES = %w(path expires domain path secure httponly samesite)
- 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
- def to_cookie_string
- select { |k, v| !CLIENT_COOKIES.include?(k.to_s.downcase) }.collect { |k, v| "#{k}=#{v}" }.join("; ")
- end
- end