Class: Pincers::Http::CookieJar
- Inherits:
-
Object
- Object
- Pincers::Http::CookieJar
- Defined in:
- lib/pincers/http/cookie_jar.rb
Constant Summary collapse
- BAD_VALUE_CHARS =
RFC 6265 - 4.1.1
/([\x00-\x20\x7F",;\\])/
Instance Attribute Summary collapse
-
#cookies ⇒ Object
readonly
Returns the value of attribute cookies.
Instance Method Summary collapse
- #copy ⇒ Object
- #for_origin(_uri) ⇒ Object
- #for_origin_as_header(_uri) ⇒ Object
- #get(_url, _name) ⇒ Object
-
#initialize(_cookies = nil) ⇒ CookieJar
constructor
A new instance of CookieJar.
- #set(_cookie) ⇒ Object
- #set_from_header(_uri, _header) ⇒ Object
- #set_raw(_request_uri, _raw) ⇒ Object
Constructor Details
#initialize(_cookies = nil) ⇒ CookieJar
Returns a new instance of CookieJar.
11 12 13 |
# File 'lib/pincers/http/cookie_jar.rb', line 11 def initialize(=nil) @cookies = || [] end |
Instance Attribute Details
#cookies ⇒ Object (readonly)
Returns the value of attribute cookies.
9 10 11 |
# File 'lib/pincers/http/cookie_jar.rb', line 9 def @cookies end |
Instance Method Details
#copy ⇒ Object
15 16 17 |
# File 'lib/pincers/http/cookie_jar.rb', line 15 def copy self.class.new @cookies.clone end |
#for_origin(_uri) ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/pincers/http/cookie_jar.rb', line 51 def for_origin(_uri) # RFC 6265 5.4.1 @cookies.select do |c| # TODO: add scheme and host only checks domains_match c.domain, _uri.host and paths_match c.path, _uri.path end end |
#for_origin_as_header(_uri) ⇒ Object
59 60 61 |
# File 'lib/pincers/http/cookie_jar.rb', line 59 def for_origin_as_header(_uri) for_origin(_uri).map { |c| "#{c.name}=#{quote(c.value)}" }.join('; ') end |
#get(_url, _name) ⇒ Object
19 20 21 |
# File 'lib/pincers/http/cookie_jar.rb', line 19 def get(_url, _name) for_origin(Utils.parse_uri(_url)).find { |c| c.name == _name } end |
#set(_cookie) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/pincers/http/cookie_jar.rb', line 23 def set() if .name.nil? or .value.nil? or .domain.nil? or .path.nil? raise ArgumentError, 'Invalid cookie' end @cookies.each_with_index do |, i| if equivalent(, ) @cookies[i] = return end end @cookies << end |
#set_from_header(_uri, _header) ⇒ Object
45 46 47 48 49 |
# File 'lib/pincers/http/cookie_jar.rb', line 45 def set_from_header(_uri, _header) _header.split(/, (?=\w+=)/).map do || set_raw _uri, .strip end end |
#set_raw(_request_uri, _raw) ⇒ Object
39 40 41 42 43 |
# File 'lib/pincers/http/cookie_jar.rb', line 39 def set_raw(_request_uri, _raw) = _request_uri, _raw set unless .nil? end |