Class: HTTPX::Plugins::Cookies::Store
- Inherits:
-
Object
- Object
- HTTPX::Plugins::Cookies::Store
- Defined in:
- lib/httpx/plugins/cookies.rb
Instance Method Summary collapse
- #[](uri) ⇒ Object
-
#initialize(cookies = nil) ⇒ Store
constructor
A new instance of Store.
- #set(origin, cookies) ⇒ Object
Constructor Details
#initialize(cookies = nil) ⇒ Store
Returns a new instance of Store.
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/httpx/plugins/cookies.rb', line 28 def initialize( = nil) @store = Hash.new { |hash, origin| hash[origin] = HTTP::CookieJar.new } return unless = .split(/ *; */) if .is_a?(String) @default_cookies = .map do |, v| if .is_a?(HTTP::Cookie) else HTTP::Cookie.new(.to_s, v.to_s) end end end |
Instance Method Details
#[](uri) ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/httpx/plugins/cookies.rb', line 48 def [](uri) store = @store[uri.origin] @default_cookies.each do || c = .dup c.domain ||= uri. c.path ||= uri.path store.add(c) end if @default_cookies store end |
#set(origin, cookies) ⇒ Object
42 43 44 45 46 |
# File 'lib/httpx/plugins/cookies.rb', line 42 def set(origin, ) return unless @store[origin].parse(, origin) end |