class HTTPX::Plugins::Cookies::Store

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

Methods

Public Class

  1. new
  2. new

Public Instance

  1. ==
  2. []
  3. set

Public Class methods

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

Public Instance methods

== (other)
[show source]
   # File lib/httpx/plugins/cookies.rb
67 def ==(other)
68   @store == other.instance_variable_get(:@store)
69 end
[] (uri)
[show source]
   # File lib/httpx/plugins/cookies.rb
56 def [](uri)
57   store = @store[uri.origin]
58   @default_cookies.each do |cookie|
59     c = cookie.dup
60     c.domain ||= uri.authority
61     c.path ||= uri.path
62     store.add(c)
63   end if @default_cookies
64   store
65 end
set (origin, cookies)
[show source]
   # File lib/httpx/plugins/cookies.rb
50 def set(origin, cookies)
51   return unless cookies
52 
53   @store[origin].parse(cookies, origin)
54 end