* lib/webrick/cookie.rb (WEBrick::Cookie.parse_set_cookies): new
method to parse multiple cookies per Set-Cookie header. Thanks to Aaron Patterson <aaron_patterson at speakeasy.net>. [ruby-core:08802] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10885 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
eba74dc219
commit
b2a8ca6dd6
@ -1,3 +1,10 @@
|
||||
Fri Sep 8 10:00:12 2006 GOTOU Yuuzou <gotoyuzo@notwork.org>
|
||||
|
||||
* lib/webrick/cookie.rb (WEBrick::Cookie.parse_set_cookies): new
|
||||
method to parse multiple cookies per Set-Cookie header.
|
||||
Thanks to Aaron Patterson <aaron_patterson at speakeasy.net>.
|
||||
[ruby-core:08802]
|
||||
|
||||
Fri Sep 8 08:59:30 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* win32/Makefile.sub, win32/configure.bat win32/setup.mak: program
|
||||
|
@ -100,5 +100,11 @@ module WEBrick
|
||||
}
|
||||
return cookie
|
||||
end
|
||||
|
||||
def self.parse_set_cookies(str)
|
||||
return str.split(/,(?=[^;,]*=)|,$/).collect{|c|
|
||||
parse_set_cookie(c)
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -70,4 +70,35 @@ class TestWEBrickCookie < Test::Unit::TestCase
|
||||
assert_equal("/acme", cookie.path)
|
||||
assert_equal(true, cookie.secure)
|
||||
end
|
||||
|
||||
def test_parse_set_cookies
|
||||
data = %(Shipping="FedEx"; Version="1"; Path="/acme"; Secure)
|
||||
data << %(, CUSTOMER=WILE_E_COYOTE; path=/; expires=Wednesday, 09-Nov-99 23:12:40 GMT; path=/; Secure)
|
||||
data << %(, name="Aaron"; Version="1"; path="/acme")
|
||||
cookies = WEBrick::Cookie.parse_set_cookies(data)
|
||||
assert_equal(3, cookies.length)
|
||||
|
||||
fed_ex = cookies.find { |c| c.name == 'Shipping' }
|
||||
assert_not_nil(fed_ex)
|
||||
assert_equal("Shipping", fed_ex.name)
|
||||
assert_equal("FedEx", fed_ex.value)
|
||||
assert_equal(1, fed_ex.version)
|
||||
assert_equal("/acme", fed_ex.path)
|
||||
assert_equal(true, fed_ex.secure)
|
||||
|
||||
name = cookies.find { |c| c.name == 'name' }
|
||||
assert_not_nil(name)
|
||||
assert_equal("name", name.name)
|
||||
assert_equal("Aaron", name.value)
|
||||
assert_equal(1, name.version)
|
||||
assert_equal("/acme", name.path)
|
||||
|
||||
customer = cookies.find { |c| c.name == 'CUSTOMER' }
|
||||
assert_not_nil(customer)
|
||||
assert_equal("CUSTOMER", customer.name)
|
||||
assert_equal("WILE_E_COYOTE", customer.value)
|
||||
assert_equal(0, customer.version)
|
||||
assert_equal("/", customer.path)
|
||||
assert_equal(Time.utc(1999, 11, 9, 23, 12, 40), customer.expires)
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user