mirror of
https://github.com/samsonjs/http-cookie.git
synced 2026-04-24 14:27:39 +00:00
HTTP::CookieJar#each: Take an optional URL/URI which is used as a scope.
Do not call cleanup in each or cookies.
This commit is contained in:
parent
7c5ac21d0f
commit
7fa5b10df6
1 changed files with 15 additions and 9 deletions
|
|
@ -32,11 +32,11 @@ class HTTP::CookieJar
|
||||||
end
|
end
|
||||||
alias << add
|
alias << add
|
||||||
|
|
||||||
# Fetch the cookies that should be used for the URI object passed in.
|
# Fetch the cookies that should be used for the URL/URI.
|
||||||
def cookies(url)
|
def cookies(url)
|
||||||
now = Time.now
|
now = Time.now
|
||||||
select { |cookie|
|
each(url).select { |cookie|
|
||||||
!cookie.expired? && cookie.valid_for_uri?(url) && (cookie.accessed_at = now)
|
!cookie.expired? && (cookie.accessed_at = now)
|
||||||
}.sort
|
}.sort
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -44,14 +44,20 @@ class HTTP::CookieJar
|
||||||
cookies(url).empty?
|
cookies(url).empty?
|
||||||
end
|
end
|
||||||
|
|
||||||
def each
|
# Iterate over cookies. If +uri+ is given, cookies not for the
|
||||||
block_given? or return enum_for(__method__)
|
# URL/URI are excluded.
|
||||||
cleanup
|
def each(uri = nil, &block)
|
||||||
|
block_given? or return enum_for(__method__, uri)
|
||||||
|
|
||||||
|
if uri
|
||||||
|
block = proc { |cookie|
|
||||||
|
yield cookie if cookie.valid_for_uri?(uri)
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
@jar.each { |domain, paths|
|
@jar.each { |domain, paths|
|
||||||
paths.each { |path, hash|
|
paths.each { |path, hash|
|
||||||
hash.each_value { |cookie|
|
hash.each_value(&block)
|
||||||
yield cookie
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self
|
self
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue