Updated HTTP_COOKIE, enable to add a cookie with empty value.
Added feature to check if a date is valid rcf1123 is_valid_rfc1123_date. Added test cases related to valid cookie dates. Updated wsf_response add_cookie basedo on review comments.
This commit is contained in:
@@ -33,7 +33,6 @@ feature {NONE} -- Initialization
|
|||||||
-- Create an object instance of cookie with name `a_name' and value `a_value'.
|
-- Create an object instance of cookie with name `a_name' and value `a_value'.
|
||||||
require
|
require
|
||||||
a_name_not_blank: a_name /= Void and then not a_name.is_whitespace
|
a_name_not_blank: a_name /= Void and then not a_name.is_whitespace
|
||||||
a_value_not_empty: a_value /= Void and then not a_value.is_empty
|
|
||||||
a_name_has_valid_characters: a_name /= Void and then has_valid_characters (a_name)
|
a_name_has_valid_characters: a_name /= Void and then has_valid_characters (a_name)
|
||||||
a_value_has_valid_characters: a_value /= Void and then has_valid_characters (a_value)
|
a_value_has_valid_characters: a_value /= Void and then has_valid_characters (a_value)
|
||||||
do
|
do
|
||||||
@@ -110,6 +109,16 @@ feature -- Access
|
|||||||
-- Does the Set-Cookie header include Expires attribute?
|
-- Does the Set-Cookie header include Expires attribute?
|
||||||
--|By default will include both.
|
--|By default will include both.
|
||||||
|
|
||||||
|
|
||||||
|
is_valid_rfc1123_date (a_string: READABLE_STRING_8): BOOLEAN
|
||||||
|
-- Is the date represented by `a_string' a valid rfc1123 date?
|
||||||
|
local
|
||||||
|
d: HTTP_DATE
|
||||||
|
do
|
||||||
|
create d.make_from_string (a_string)
|
||||||
|
Result := not d.has_error and then d.rfc1123_string.same_string (a_string)
|
||||||
|
end
|
||||||
|
|
||||||
feature -- Change Element
|
feature -- Change Element
|
||||||
|
|
||||||
set_name (a_name: READABLE_STRING_8)
|
set_name (a_name: READABLE_STRING_8)
|
||||||
@@ -126,7 +135,6 @@ feature -- Change Element
|
|||||||
set_value (a_value: READABLE_STRING_8)
|
set_value (a_value: READABLE_STRING_8)
|
||||||
-- Set `value' with `a_value'.
|
-- Set `value' with `a_value'.
|
||||||
require
|
require
|
||||||
a_value_not_empty: a_value /= Void and then not a_value.is_empty
|
|
||||||
a_value_has_valid_characters: a_value /= Void and then has_valid_characters (a_value)
|
a_value_has_valid_characters: a_value /= Void and then has_valid_characters (a_value)
|
||||||
do
|
do
|
||||||
value := a_value
|
value := a_value
|
||||||
@@ -136,6 +144,8 @@ feature -- Change Element
|
|||||||
|
|
||||||
set_expiration (a_date: READABLE_STRING_8)
|
set_expiration (a_date: READABLE_STRING_8)
|
||||||
-- Set `expiration' with `a_date'
|
-- Set `expiration' with `a_date'
|
||||||
|
require
|
||||||
|
rfc1133_date: a_date /= Void and then is_valid_rfc1123_date (a_date)
|
||||||
do
|
do
|
||||||
expiration := a_date
|
expiration := a_date
|
||||||
ensure
|
ensure
|
||||||
@@ -163,7 +173,7 @@ feature -- Change Element
|
|||||||
-- Note: you should avoid using "localhost" as `domain' for local cookies
|
-- Note: you should avoid using "localhost" as `domain' for local cookies
|
||||||
-- since they are not always handled by browser (for instance Chrome)
|
-- since they are not always handled by browser (for instance Chrome)
|
||||||
require
|
require
|
||||||
domain_without_port_info: a_domain /= Void implies a_domain.index_of (':', 1) = 0
|
domain_without_port_info: a_domain /= Void implies not a_domain.has (':')
|
||||||
do
|
do
|
||||||
domain := a_domain
|
domain := a_domain
|
||||||
ensure
|
ensure
|
||||||
|
|||||||
@@ -36,6 +36,15 @@ feature -- Test routines
|
|||||||
assert ("Not valid Dquote", not l_cookie.has_valid_characters ("Use!%"12"))
|
assert ("Not valid Dquote", not l_cookie.has_valid_characters ("Use!%"12"))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test_cookie_empty_value
|
||||||
|
-- values (cookie name and value)
|
||||||
|
local
|
||||||
|
l_cookie: HTTP_COOKIE
|
||||||
|
do
|
||||||
|
create l_cookie.make ("user_id", "")
|
||||||
|
assert("Expected", l_cookie.header_line.same_string ("Set-Cookie: user_id=; Max-Age=-1"))
|
||||||
|
end
|
||||||
|
|
||||||
test_cookie_full_attributes
|
test_cookie_full_attributes
|
||||||
local
|
local
|
||||||
l_cookie: HTTP_COOKIE
|
l_cookie: HTTP_COOKIE
|
||||||
@@ -124,6 +133,22 @@ feature -- Test routines
|
|||||||
assert("Expected", l_cookie.header_line.same_string ("Set-Cookie: user_id=u12345; Max-Age=120"))
|
assert("Expected", l_cookie.header_line.same_string ("Set-Cookie: user_id=u12345; Max-Age=120"))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test_cookie_date_rfc1123_valid
|
||||||
|
local
|
||||||
|
l_cookie: HTTP_COOKIE
|
||||||
|
do
|
||||||
|
create l_cookie.make ("user_id", "u12345")
|
||||||
|
assert ("Valid RFC1123", l_cookie.is_valid_rfc1123_date ("Thu, 19 Mar 2015 16:14:03 GMT"))
|
||||||
|
end
|
||||||
|
|
||||||
|
test_cookie_date_rfc1123_invalid
|
||||||
|
local
|
||||||
|
l_cookie: HTTP_COOKIE
|
||||||
|
do
|
||||||
|
create l_cookie.make ("user_id", "u12345")
|
||||||
|
assert ("Invalid RFC1123", not l_cookie.is_valid_rfc1123_date ("Thuesday, 19 Mar 2015 16:14:03 GMT"))
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -331,7 +331,7 @@ feature -- Header add cookie
|
|||||||
internal_header.headers as ic
|
internal_header.headers as ic
|
||||||
until l_same_cookie_name
|
until l_same_cookie_name
|
||||||
loop
|
loop
|
||||||
if is_cookie_line (ic.item) then
|
if ic.item.starts_with ("Set-Cookie:") then
|
||||||
l_same_cookie_name := has_cookie_name (ic.item, a_cookie.name)
|
l_same_cookie_name := has_cookie_name (ic.item, a_cookie.name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -560,24 +560,7 @@ feature {NONE} -- Implemenation
|
|||||||
from until not a_cookie_line[j].is_space loop
|
from until not a_cookie_line[j].is_space loop
|
||||||
j := j + 1
|
j := j + 1
|
||||||
end
|
end
|
||||||
if a_cookie_line.substring (j, i).same_string (a_cookie_name) then
|
if a_cookie_name.same_characters (a_cookie_line, j, i, 1) then
|
||||||
Result := True
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
is_cookie_line (a_line: READABLE_STRING_32): BOOLEAN
|
|
||||||
-- Is the line `a_line' a cookie line?
|
|
||||||
--| Set-Cookie: user_id=%"u12;345%"; Domain=www.example.com; Path=/; Expires=Sat, 18 Apr 2015 21:22:05 GMT; Max-Age=-1; Secure; HttpOnly
|
|
||||||
local
|
|
||||||
j: INTEGER
|
|
||||||
do
|
|
||||||
Result := False
|
|
||||||
j := a_line.index_of (':', 1)
|
|
||||||
if j > 0 then
|
|
||||||
j := j - 1
|
|
||||||
if a_line.substring (1, j).same_string ("Set-Cookie") then
|
|
||||||
Result := True
|
Result := True
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user