Skip to content

Commit 08db074

Browse files
committed
Updated is_valid_character, using NATURAL_32 as an argument to avoid multiple conversions.
Updated add_cookie, added features has_cookie_name and is_cookie line to avoid the use of STRING.split and STRING.start_with.
1 parent 9dc22be commit 08db074

File tree

3 files changed

+46
-10
lines changed

3 files changed

+46
-10
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ feature -- Access
9595
until
9696
l_found
9797
loop
98-
if not is_valid_character (ic.item.to_character_8) then
98+
if not is_valid_character (ic.item.natural_32_code) then
9999
Result := False
100100
l_found := True
101101
end
@@ -304,7 +304,7 @@ feature {NONE} -- Constants
304304
end
305305

306306

307-
is_valid_character (c: CHARACTER): BOOLEAN
307+
is_valid_character (c: NATURAL_32): BOOLEAN
308308
-- RFC6265 that specifies that the following is valid for characters in cookies.
309309
-- The following character ranges are valid:http://tools.ietf.org/html/rfc6265#section-4.1.1
310310
-- %x21 / %x23-2B / %x2D-3A / %x3C-5B / %x5D-7E
@@ -317,7 +317,7 @@ feature {NONE} -- Constants
317317
EIS: "name=valid-characters", "src=http://tools.ietf.org/html/rfc6265#section-4.1.1", "protocol=uri"
318318
do
319319
Result := True
320-
inspect c.natural_32_code
320+
inspect c
321321
when 0x21 then
322322
when 0x23 .. 0x2B then
323323
when 0x2D .. 0x3A then

library/server/wsf/src/wsf_response.e

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -331,12 +331,8 @@ feature -- Header add cookie
331331
internal_header.headers as ic
332332
until l_same_cookie_name
333333
loop
334-
if ic.item.starts_with ("Set-Cookie") then
335-
l_nv := ic.item.split (';').at (1).split (':').at (2)
336-
l_nv.adjust
337-
if l_nv.starts_with (a_cookie.name) then
338-
l_same_cookie_name := True
339-
end
334+
if is_cookie_line (ic.item) then
335+
l_same_cookie_name := has_cookie_name (ic.item, a_cookie.name)
340336
end
341337
end
342338
if not l_same_cookie_name then
@@ -547,6 +543,46 @@ feature -- Error reporting
547543
wgi_response.put_error (a_message)
548544
end
549545
546+
feature {NONE} -- Implemenation
547+
548+
has_cookie_name (a_cookie_line, a_cookie_name: READABLE_STRING_32 ): BOOLEAN
549+
-- Has the cookie line `a_cookie_line', the cookie name `a_cookie_name'?
550+
local
551+
i,j: INTEGER
552+
do
553+
Result := False
554+
i := a_cookie_line.index_of ('=', 1)
555+
j := a_cookie_line.index_of (':', 1)
556+
557+
if i > j and j > 0 then
558+
i := i - 1
559+
j := j + 1
560+
from until not a_cookie_line[j].is_space loop
561+
j := j + 1
562+
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
581+
Result := True
582+
end
583+
end
584+
end
585+
550586
note
551587
copyright: "2011-2015, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Colin Adams, Eiffel Software and others"
552588
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"

library/server/wsf/tests/src/wgi_response_null.e

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ feature -- Error reporting
124124
end
125125
end
126126

127-
feature {EQA_TEST_SET} -- Implementation: Access
127+
feature -- Implementation: Access
128128

129129
output: STRING
130130
-- Server output channel

0 commit comments

Comments
 (0)