class HTTPX::Plugins::Cookies::Store

  1. lib/httpx/plugins/cookies.rb
Superclass: Object

Methods

Public Class

  1. new

Public Instance

  1. ==
  2. []
  3. set

Public Class methods

new (cookies = nil)
[show source]
   # File lib/httpx/plugins/cookies.rb
28 def initialize(cookies = nil)
29   @store = Hash.new { |hash, origin| hash[origin] = HTTP::CookieJar.new }
30   return unless cookies
31 
32   cookies = cookies.split(/ *; */) if cookies.is_a?(String)
33   @default_cookies = cookies.map do |cookie, v|
34     if cookie.is_a?(HTTP::Cookie)
35       cookie
36     else
37       HTTP::Cookie.new(cookie.to_s, v.to_s)
38     end
39   end
40 end

Public Instance methods

== (other)
[show source]
   # File lib/httpx/plugins/cookies.rb
59 def ==(other)
60   @store == other.instance_variable_get(:@store)
61 end
[] (uri)
[show source]
   # File lib/httpx/plugins/cookies.rb
48 def [](uri)
49   store = @store[uri.origin]
50   @default_cookies.each do |cookie|
51     c = cookie.dup
52     c.domain ||= uri.authority
53     c.path ||= uri.path
54     store.add(c)
55   end if @default_cookies
56   store
57 end
set (origin, cookies)
[show source]
   # File lib/httpx/plugins/cookies.rb
42 def set(origin, cookies)
43   return unless cookies
44 
45   @store[origin].parse(cookies, origin)
46 end