mirror of
https://github.com/samsonjs/http-cookie.git
synced 2026-03-25 08:55:53 +00:00
Add CookieJar#delete().
This commit is contained in:
parent
2ef3e42067
commit
f3b8abdd8e
2 changed files with 29 additions and 9 deletions
|
|
@ -74,6 +74,17 @@ class HTTP::CookieJar
|
||||||
end
|
end
|
||||||
alias << add
|
alias << add
|
||||||
|
|
||||||
|
# Deletes a cookie that has the same name, domain and path as a
|
||||||
|
# given cookie from the jar and returns self.
|
||||||
|
#
|
||||||
|
# How the `for_domain` flag value affects the set of deleted cookies
|
||||||
|
# depends on the store used. See individual store classes for that
|
||||||
|
# matter.
|
||||||
|
def delete(cookie)
|
||||||
|
@store.delete(cookie)
|
||||||
|
self
|
||||||
|
end
|
||||||
|
|
||||||
# Gets an array of cookies that should be sent for the URL/URI,
|
# Gets an array of cookies that should be sent for the URL/URI,
|
||||||
# updating the access time of each cookie.
|
# updating the access time of each cookie.
|
||||||
def cookies(url)
|
def cookies(url)
|
||||||
|
|
|
||||||
|
|
@ -554,17 +554,26 @@ module TestHTTPCookieJar
|
||||||
assert_equal('Foo1 Foo2', @jar.cookies(surl).map { |c| c.name }.sort.join(' ') )
|
assert_equal('Foo1 Foo2', @jar.cookies(surl).map { |c| c.name }.sort.join(' ') )
|
||||||
end
|
end
|
||||||
|
|
||||||
def _test_delete
|
def test_delete
|
||||||
nurl = URI 'http://rubyforge.org/login'
|
cookie1 = HTTP::Cookie.new(cookie_values)
|
||||||
surl = URI 'https://rubyforge.org/login'
|
cookie2 = HTTP::Cookie.new(:name => 'Foo', :value => '',
|
||||||
|
:domain => 'rubyforge.org',
|
||||||
|
:for_domain => false,
|
||||||
|
:path => '/')
|
||||||
|
cookie3 = HTTP::Cookie.new(:name => 'Foo', :value => '',
|
||||||
|
:domain => 'rubyforge.org',
|
||||||
|
:for_domain => true,
|
||||||
|
:path => '/')
|
||||||
|
|
||||||
cookie1 = HTTP::Cookie.new(cookie_values(:name => 'Foo1', :origin => nurl))
|
@jar.add(cookie1)
|
||||||
cookie2 = HTTP::Cookie.new(cookie_values(:name => 'Foo1', :origin => surl))
|
@jar.delete(cookie2)
|
||||||
|
|
||||||
@jar.add(nncookie)
|
if mozilla_store?
|
||||||
@jar.add(sncookie)
|
assert_equal(1, @jar.to_a.length)
|
||||||
@jar.add(nscookie)
|
@jar.delete(cookie3)
|
||||||
@jar.add(sscookie)
|
end
|
||||||
|
|
||||||
|
assert_equal(0, @jar.to_a.length)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_max_cookies
|
def test_max_cookies
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue