mirror of
https://github.com/samsonjs/http-cookie.git
synced 2026-04-27 14:57:46 +00:00
Make each(uri) not fail if a non-HTTP URL is given.
Fix documents with #each. The uri argument was not made a keyword argument. Guarantee that the +uri+ given to AbstractStore#each() is a URI object. Make HashStore#each return self as required.
This commit is contained in:
parent
9d3975f641
commit
8be03978a0
4 changed files with 18 additions and 22 deletions
|
|
@ -67,21 +67,19 @@ class HTTP::CookieJar
|
||||||
|
|
||||||
# Iterates over all cookies that are not expired.
|
# Iterates over all cookies that are not expired.
|
||||||
#
|
#
|
||||||
# Available option keywords are below:
|
# An optional argument +uri+ specifies a URI/URL indicating the
|
||||||
|
# destination of the cookies being selected. Every cookie yielded
|
||||||
|
# should be good to send to the given URI,
|
||||||
|
# i.e. cookie.valid_for_uri?(uri) evaluates to true.
|
||||||
#
|
#
|
||||||
# * +uri+
|
# If (and only if) the +uri+ option is given, last access time of
|
||||||
#
|
# each cookie is updated to the current time.
|
||||||
# Specify a URI/URL indicating the destination of the cookies
|
|
||||||
# being selected. Every cookie yielded should be good to send to
|
|
||||||
# the given URI, i.e. cookie.valid_for_uri?(uri) evaluates to
|
|
||||||
# true.
|
|
||||||
#
|
|
||||||
# If (and only if) this option is given, last access time of each
|
|
||||||
# cookie is updated to the current time.
|
|
||||||
def each(uri = nil, &block)
|
def each(uri = nil, &block)
|
||||||
block_given? or return enum_for(__method__, uri)
|
block_given? or return enum_for(__method__, uri)
|
||||||
|
|
||||||
if uri
|
if uri
|
||||||
|
uri = URI(uri)
|
||||||
|
return self unless URI::HTTP === uri && uri.host
|
||||||
block = proc { |cookie|
|
block = proc { |cookie|
|
||||||
yield cookie if cookie.valid_for_uri?(uri)
|
yield cookie if cookie.valid_for_uri?(uri)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -54,18 +54,14 @@ class HTTP::CookieJar::AbstractStore
|
||||||
|
|
||||||
# Iterates over all cookies that are not expired.
|
# Iterates over all cookies that are not expired.
|
||||||
#
|
#
|
||||||
# Available option keywords are below:
|
# An optional argument +uri+ specifies a URI object indicating the
|
||||||
|
# destination of the cookies being selected. Every cookie yielded
|
||||||
|
# should be good to send to the given URI,
|
||||||
|
# i.e. cookie.valid_for_uri?(uri) evaluates to true.
|
||||||
#
|
#
|
||||||
# * +uri+
|
# If (and only if) the +uri+ option is given, last access time of
|
||||||
#
|
# each cookie is updated to the current time.
|
||||||
# Specify a URI object indicating the destination of the cookies
|
def each(uri = nil, &block)
|
||||||
# being selected. Every cookie yielded should be good to send to
|
|
||||||
# the given URI, i.e. cookie.valid_for_uri?(uri) evaluates to
|
|
||||||
# true.
|
|
||||||
#
|
|
||||||
# If (and only if) this option is given, last access time of each
|
|
||||||
# cookie is updated to the current time.
|
|
||||||
def each(options = nil, &block)
|
|
||||||
raise
|
raise
|
||||||
self
|
self
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,6 @@ class HTTP::CookieJar
|
||||||
|
|
||||||
def each(uri = nil)
|
def each(uri = nil)
|
||||||
if uri
|
if uri
|
||||||
uri = URI(uri)
|
|
||||||
thost = DomainName.new(uri.host)
|
thost = DomainName.new(uri.host)
|
||||||
tpath = HTTP::Cookie.normalize_path(uri.path)
|
tpath = HTTP::Cookie.normalize_path(uri.path)
|
||||||
@jar.each { |domain, paths|
|
@jar.each { |domain, paths|
|
||||||
|
|
@ -83,6 +82,7 @@ class HTTP::CookieJar
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
self
|
||||||
end
|
end
|
||||||
|
|
||||||
def clear
|
def clear
|
||||||
|
|
|
||||||
|
|
@ -276,6 +276,8 @@ class TestHTTPCookieJar < Test::Unit::TestCase
|
||||||
assert_raises(ArgumentError) {
|
assert_raises(ArgumentError) {
|
||||||
@jar.add(HTTP::Cookie.new(cookie_values(:origin => url)))
|
@jar.add(HTTP::Cookie.new(cookie_values(:origin => url)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assert_equal(0, @jar.cookies(url).length)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_clear
|
def test_clear
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue