Skip to content

Commit 3026163

Browse files
committed
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.
1 parent 08db074 commit 3026163

File tree

3 files changed

+40
-22
lines changed

3 files changed

+40
-22
lines changed

library/network/protocol/http/src/http_cookie.e

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ feature {NONE} -- Initialization
3333
-- Create an object instance of cookie with name `a_name' and value `a_value'.
3434
require
3535
a_name_not_blank: a_name /= Void and then not a_name.is_whitespace
36-
a_value_not_empty: a_value /= Void and then not a_value.is_empty
3736
a_name_has_valid_characters: a_name /= Void and then has_valid_characters (a_name)
3837
a_value_has_valid_characters: a_value /= Void and then has_valid_characters (a_value)
3938
do
@@ -110,6 +109,16 @@ feature -- Access
110109
-- Does the Set-Cookie header include Expires attribute?
111110
--|By default will include both.
112111

112+
113+
is_valid_rfc1123_date (a_string: READABLE_STRING_8): BOOLEAN
114+
-- Is the date represented by `a_string' a valid rfc1123 date?
115+
local
116+
d: HTTP_DATE
117+
do
118+
create d.make_from_string (a_string)
119+
Result := not d.has_error and then d.rfc1123_string.same_string (a_string)
120+
end
121+
113122
feature -- Change Element
114123

115124
set_name (a_name: READABLE_STRING_8)
@@ -126,7 +135,6 @@ feature -- Change Element
126135
set_value (a_value: READABLE_STRING_8)
127136
-- Set `value' with `a_value'.
128137
require
129-
a_value_not_empty: a_value /= Void and then not a_value.is_empty
130138
a_value_has_valid_characters: a_value /= Void and then has_valid_characters (a_value)
131139
do
132140
value := a_value
@@ -136,6 +144,8 @@ feature -- Change Element
136144

137145
set_expiration (a_date: READABLE_STRING_8)
138146
-- Set `expiration' with `a_date'
147+
require
148+
rfc1133_date: a_date /= Void and then is_valid_rfc1123_date (a_date)
139149
do
140150
expiration := a_date
141151
ensure
@@ -163,7 +173,7 @@ feature -- Change Element
163173
-- Note: you should avoid using "localhost" as `domain' for local cookies
164174
-- since they are not always handled by browser (for instance Chrome)
165175
require
166-
domain_without_port_info: a_domain /= Void implies a_domain.index_of (':', 1) = 0
176+
domain_without_port_info: a_domain /= Void implies not a_domain.has (':')
167177
do
168178
domain := a_domain
169179
ensure

library/network/protocol/http/tests/http_cookie_test_set.e

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ feature -- Test routines
3636
assert ("Not valid Dquote", not l_cookie.has_valid_characters ("Use!%"12"))
3737
end
3838
39+
test_cookie_empty_value
40+
-- values (cookie name and value)
41+
local
42+
l_cookie: HTTP_COOKIE
43+
do
44+
create l_cookie.make ("user_id", "")
45+
assert("Expected", l_cookie.header_line.same_string ("Set-Cookie: user_id=; Max-Age=-1"))
46+
end
47+
3948
test_cookie_full_attributes
4049
local
4150
l_cookie: HTTP_COOKIE
@@ -124,6 +133,22 @@ feature -- Test routines
124133
assert("Expected", l_cookie.header_line.same_string ("Set-Cookie: user_id=u12345; Max-Age=120"))
125134
end
126135
136+
test_cookie_date_rfc1123_valid
137+
local
138+
l_cookie: HTTP_COOKIE
139+
do
140+
create l_cookie.make ("user_id", "u12345")
141+
assert ("Valid RFC1123", l_cookie.is_valid_rfc1123_date ("Thu, 19 Mar 2015 16:14:03 GMT"))
142+
end
143+
144+
test_cookie_date_rfc1123_invalid
145+
local
146+
l_cookie: HTTP_COOKIE
147+
do
148+
create l_cookie.make ("user_id", "u12345")
149+
assert ("Invalid RFC1123", not l_cookie.is_valid_rfc1123_date ("Thuesday, 19 Mar 2015 16:14:03 GMT"))
150+
end
151+
127152
128153
end
129154

library/server/wsf/src/wsf_response.e

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ feature -- Header add cookie
331331
internal_header.headers as ic
332332
until l_same_cookie_name
333333
loop
334-
if is_cookie_line (ic.item) then
334+
if ic.item.starts_with ("Set-Cookie:") then
335335
l_same_cookie_name := has_cookie_name (ic.item, a_cookie.name)
336336
end
337337
end
@@ -560,24 +560,7 @@ feature {NONE} -- Implemenation
560560
from until not a_cookie_line[j].is_space loop
561561
j := j + 1
562562
end
563-
if a_cookie_line.substring (j, i).same_string (a_cookie_name) then
564-
Result := True
565-
end
566-
end
567-
end
568-
569-
570-
is_cookie_line (a_line: READABLE_STRING_32): BOOLEAN
571-
-- Is the line `a_line' a cookie line?
572-
--| 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
573-
local
574-
j: INTEGER
575-
do
576-
Result := False
577-
j := a_line.index_of (':', 1)
578-
if j > 0 then
579-
j := j - 1
580-
if a_line.substring (1, j).same_string ("Set-Cookie") then
563+
if a_cookie_name.same_characters (a_cookie_line, j, i, 1) then
581564
Result := True
582565
end
583566
end

0 commit comments

Comments
 (0)