mirror of
https://github.com/samsonjs/http-cookie.git
synced 2026-04-27 14:57:46 +00:00
Add a utility shorthand method HTTP::CookieJar#parse.
This commit is contained in:
parent
dc65a98907
commit
1c140c035d
1 changed files with 23 additions and 0 deletions
|
|
@ -117,6 +117,29 @@ class HTTP::CookieJar
|
||||||
end
|
end
|
||||||
include Enumerable
|
include Enumerable
|
||||||
|
|
||||||
|
# Parses a Set-Cookie field value `set_cookie` sent from a URI
|
||||||
|
# `origin` and adds the cookies parsed as valid to the jar. Returns
|
||||||
|
# an array of cookies that have been added. If a block is given, it
|
||||||
|
# is called after each cookie is added.
|
||||||
|
#
|
||||||
|
# `jar.parse(set_cookie, origin)` is a shorthand for this:
|
||||||
|
#
|
||||||
|
# HTTP::Cookie.parse(set_cookie, origin) { |cookie|
|
||||||
|
# jar.add(cookie)
|
||||||
|
# }
|
||||||
|
#
|
||||||
|
# See HTTP::Cookie.parse for available options.
|
||||||
|
def parse(set_cookie, origin, options = nil) # :yield: cookie
|
||||||
|
if block_given?
|
||||||
|
HTTP::Cookie.parse(set_cookie, origin, options) { |cookie|
|
||||||
|
add(cookie)
|
||||||
|
yield cookie
|
||||||
|
}
|
||||||
|
else
|
||||||
|
HTTP::Cookie.parse(set_cookie, origin, options, &method(:add))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# call-seq:
|
# call-seq:
|
||||||
# jar.save(filename_or_io, **options)
|
# jar.save(filename_or_io, **options)
|
||||||
# jar.save(filename_or_io, format = :yaml, **options)
|
# jar.save(filename_or_io, format = :yaml, **options)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue