PageRenderTime 344ms CodeModel.GetById 171ms app.highlight 5ms RepoModel.GetById 116ms app.codeStats 50ms

/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
 1class HTTParty::CookieHash < Hash #:nodoc:
 2  CLIENT_COOKIES = %w(path expires domain path secure httponly samesite)
 3
 4  def add_cookies(data)
 5    case data
 6    when Hash
 7      merge!(data)
 8    when String
 9      data.split('; ').each do |cookie|
10        key, value = cookie.split('=', 2)
11        self[key.to_sym] = value if key
12      end
13    else
14      raise "add_cookies only takes a Hash or a String"
15    end
16  end
17
18  def to_cookie_string
19    select { |k, v| !CLIENT_COOKIES.include?(k.to_s.downcase) }.collect { |k, v| "#{k}=#{v}" }.join("; ")
20  end
21end