Class: Buzz::CookieJar
- Inherits:
-
Object
- Object
- Buzz::CookieJar
- Defined in:
- lib/buzz/cookie_jar.rb
Defined Under Namespace
Classes: Cookie
Instance Method Summary collapse
- #clear ⇒ Object
- #cookie_header(uri) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize ⇒ CookieJar
constructor
A new instance of CookieJar.
- #parse(set_cookie_header, request_uri) ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize ⇒ CookieJar
Returns a new instance of CookieJar.
10 11 12 13 |
# File 'lib/buzz/cookie_jar.rb', line 10 def initialize @cookies = {} @mutex = Mutex.new end |
Instance Method Details
#clear ⇒ Object
45 46 47 |
# File 'lib/buzz/cookie_jar.rb', line 45 def clear @mutex.synchronize { @cookies.clear } end |
#cookie_header(uri) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/buzz/cookie_jar.rb', line 29 def (uri) uri = uri.is_a?(URI) ? uri : URI.parse(uri) now = Time.now @mutex.synchronize do matching = @cookies.values.select do || next false if .expires && .expires < now next false if .secure && uri.scheme != "https" path_matches?(uri.path, .path) end return nil if matching.empty? matching.map { |c| "#{c.name}=#{c.value}" }.join("; ") end end |
#empty? ⇒ Boolean
49 50 51 |
# File 'lib/buzz/cookie_jar.rb', line 49 def empty? @mutex.synchronize { @cookies.empty? } end |
#parse(set_cookie_header, request_uri) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/buzz/cookie_jar.rb', line 15 def parse(, request_uri) return unless headers = .is_a?(Array) ? : [] uri = request_uri.is_a?(URI) ? request_uri : URI.parse(request_uri) @mutex.synchronize do headers.each do |header| = (header, uri) @cookies[.name] = if end end end |
#size ⇒ Object
53 54 55 |
# File 'lib/buzz/cookie_jar.rb', line 53 def size @mutex.synchronize { @cookies.size } end |