Updated HTTP_COOKIE class based on comments.

Added missing descriptions in test classes
This commit is contained in:
jvelilla
2015-03-17 17:00:07 -03:00
parent c4d362ff31
commit 9dc22bee24
4 changed files with 69 additions and 68 deletions

View File

@@ -1,21 +1,21 @@
note note
description: "[ description: "[
This class represents the value of a HTTP cookie, transferred in a request. This class represents the value of a HTTP cookie, transferred in a request.
The class has features to build an HTTP cookie. The class has features to build an HTTP cookie.
Following a newer RFC standard for Cookies http://tools.ietf.org/html/rfc6265 Following a newer RFC standard for Cookies http://tools.ietf.org/html/rfc6265
Domain Domain
* WARNING: Some existing user agents treat an absent Domain attribute as if the Domain attribute were present and contained the current host name. * WARNING: Some existing user agents treat an absent Domain attribute as if the Domain attribute were present and contained the current host name.
* For example, if example.com returns a Set-Cookie header without a Domain attribute, these user agents will erroneously send the cookie to www.example.com as well. * For example, if example.com returns a Set-Cookie header without a Domain attribute, these user agents will erroneously send the cookie to www.example.com as well.
Max-Age, Expires Max-Age, Expires
* If a cookie has both the Max-Age and the Expires attribute, the Max-Age attribute has precedence and controls the expiration date of the cookie. * If a cookie has both the Max-Age and the Expires attribute, the Max-Age attribute has precedence and controls the expiration date of the cookie.
* If a cookie has neither the Max-Age nor the Expires attribute, the user agent will retain the cookie until "the current session is over" (as defined by the user agent). * If a cookie has neither the Max-Age nor the Expires attribute, the user agent will retain the cookie until "the current session is over" (as defined by the user agent).
* You will need to call the feature * You will need to call the feature
HttpOnly, Secure HttpOnly, Secure
* Note that the HttpOnly attribute is independent of the Secure attribute: a cookie can have both the HttpOnly and the Secure attribute. * Note that the HttpOnly attribute is independent of the Secure attribute: a cookie can have both the HttpOnly and the Secure attribute.
]" ]"
date: "$Date$" date: "$Date$"
@@ -32,7 +32,10 @@ feature {NONE} -- Initialization
make (a_name: READABLE_STRING_8; a_value: READABLE_STRING_8) make (a_name: READABLE_STRING_8; a_value: READABLE_STRING_8)
-- 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
make_sense: (a_name /= Void and a_value /= Void) and then (not a_name.is_empty and not a_value.is_empty) 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_value_has_valid_characters: a_value /= Void and then has_valid_characters (a_value)
do do
set_name (a_name) set_name (a_name)
set_value(a_value) set_value(a_value)
@@ -66,33 +69,33 @@ feature -- Access
secure: BOOLEAN secure: BOOLEAN
-- Value of the Secure attribute. -- Value of the Secure attribute.
-- By default False. -- By default False.
--| Idicate if the cookie should only be sent over secured(encrypted connections, for example SSL). --| Indicate if the cookie should only be sent over secured(encrypted connections, for example SSL).
http_only: BOOLEAN http_only: BOOLEAN
-- Value of the http_only attribute. -- Value of the http_only attribute.
-- By default false. -- By default false.
--| Limits the scope of the cookie to HTTP requests. --| Limits the scope of the cookie to HTTP requests.
max_age: INTEGER max_age: INTEGER
-- Value of the Max-Age attribute. -- Value of the Max-Age attribute.
--| How much time in seconds should elapsed before the cooki expires. --| How much time in seconds should elapsed before the cookie expires.
--| By default max_age < 0 indicate a cookie will last only for the current user-agent (Browser, etc) session. --| By default max_age < 0 indicate a cookie will last only for the current user-agent (Browser, etc) session.
--| A value of 0 instructs the user-agent to delete the cookie. --| A value of 0 instructs the user-agent to delete the cookie.
has_valid_characters (a_name: READABLE_STRING_GENERAL):BOOLEAN has_valid_characters (a_name: READABLE_STRING_8):BOOLEAN
-- Has `a_name' valid characters for cookies? -- Has `a_name' valid characters for cookies?
local local
l_iterator: STRING_ITERATION_CURSOR l_iterator: STRING_ITERATION_CURSOR
l_found: BOOLEAN l_found: BOOLEAN
do do
create l_iterator.make (a_name) create l_iterator.make (a_name)
Result := True
across across
l_iterator as ic l_iterator as ic
until until
l_found l_found
loop loop
if is_valid_character (ic.item.to_character_8) then if not is_valid_character (ic.item.to_character_8) then
Result := False Result := False
l_found := True l_found := True
end end
@@ -100,37 +103,43 @@ feature -- Access
end end
include_max_age: BOOLEAN include_max_age: BOOLEAN
-- Does the Set-Cookie header will include Max-Age attribute? -- Does the Set-Cookie header include Max-Age attribute?
--|By default will include both. --|By default will include both.
include_expires: BOOLEAN include_expires: BOOLEAN
-- Does the Set-Cookie header will include Expires attribute? -- Does the Set-Cookie header include Expires attribute?
--|By default will include both. --|By default will include both.
feature -- Change Element feature -- Change Element
set_name (a_name: READABLE_STRING_GENERAL) set_name (a_name: READABLE_STRING_8)
-- Set `name' with `a_name'. -- Set `name' with `a_name'.
require
a_name_not_blank: a_name /= Void and then not a_name.is_whitespace
a_name_has_valid_characters: a_name /= Void and then has_valid_characters (a_name)
do do
name := a_name.as_string_8 name := a_name
ensure ensure
name_set: name = a_name name_set: name = a_name
end end
set_value (a_value: READABLE_STRING_GENERAL) set_value (a_value: READABLE_STRING_8)
-- Set `value' with `a_value'. -- Set `value' with `a_value'.
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)
do do
value := a_value.as_string_8 value := a_value
ensure ensure
value_set: value = a_value value_set: value = a_value
end end
set_expiration (a_date: READABLE_STRING_GENERAL) set_expiration (a_date: READABLE_STRING_8)
-- Set `expiration' with `a_date' -- Set `expiration' with `a_date'
do do
expiration := a_date.as_string_32 expiration := a_date
ensure ensure
expiration_set: attached expiration as l_expiration and then l_expiration.same_string (a_date.as_string_8) expiration_set: attached expiration as l_expiration and then l_expiration.same_string (a_date)
end end
set_expiration_date (a_date: DATE_TIME) set_expiration_date (a_date: DATE_TIME)
@@ -141,22 +150,22 @@ feature -- Change Element
expiration_set: attached expiration as l_expiration and then l_expiration.same_string (date_to_rfc1123_http_date_format (a_date)) expiration_set: attached expiration as l_expiration and then l_expiration.same_string (date_to_rfc1123_http_date_format (a_date))
end end
set_path (a_path: READABLE_STRING_GENERAL) set_path (a_path: READABLE_STRING_8)
-- Set `path' with `a_path' -- Set `path' with `a_path'
do do
path := a_path.as_string_8 path := a_path
ensure ensure
path_set: path = a_path path_set: path = a_path
end end
set_domain (a_domain: READABLE_STRING_GENERAL) set_domain (a_domain: READABLE_STRING_8)
-- Set `domain' with `a_domain' -- Set `domain' with `a_domain'
-- 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 a_domain.index_of (':', 1) = 0
do do
domain := a_domain.as_string_8 domain := a_domain
ensure ensure
domain_set: domain = a_domain domain_set: domain = a_domain
end end
@@ -218,11 +227,11 @@ feature -- Change Element
include_expires := False include_expires := False
include_max_age := False include_max_age := False
ensure ensure
expires_false: not include_expires expires_false: not include_expires
max_age_false: not include_max_age max_age_false: not include_max_age
end end
feature -- Date Utils feature {NONE} -- Date Utils
date_to_rfc1123_http_date_format (dt: DATE_TIME): STRING_8 date_to_rfc1123_http_date_format (dt: DATE_TIME): STRING_8
-- String representation of `dt' using the RFC 1123 -- String representation of `dt' using the RFC 1123
@@ -236,7 +245,7 @@ feature -- Date Utils
feature -- Output feature -- Output
header_line: STRING header_line: STRING
-- String representation of Set-Cookie header of current. -- String representation of Set-Cookie header line of Current.
local local
s: STRING s: STRING
do do
@@ -260,17 +269,21 @@ feature -- Output
-- Max-Age -- Max-Age
elseif include_max_age then elseif include_max_age then
s.append ("; Max-Age=") s.append ("; Max-Age=")
s.append (max_age.out) s.append_integer (max_age)
else else
-- Default -- Default
check default: (not include_expires) and (not include_max_age) end check
-- By default the attributes include_expires and include_max_age are False.
-- Meaning that Expires and Max-Age headers are included in the response.
default: (not include_expires) and (not include_max_age)
end
if attached expiration as l_expires then if attached expiration as l_expires then
s.append ("; Expires=") s.append ("; Expires=")
s.append (l_expires) s.append (l_expires)
end end
s.append ("; Max-Age=") s.append ("; Max-Age=")
s.append (max_age.out) s.append_integer (max_age)
end end
if secure then if secure then
@@ -291,24 +304,8 @@ feature {NONE} -- Constants
end end
legal_characters, valid_characters: SPECIAL [CHARACTER_8]
-- RFC6265 that specifies that the following is valid for characters in cookies. Cookies are also supposed to be double quoted.
-- The following character ranges are valid:http://tools.ietf.org/html/rfc6265#section-4.1.1
-- %x21 / %x23-2B / %x2D-3A / %x3C-5B / %x5D-7E
-- 0x21: !
-- 0x23-2B: #$%&'()*+
-- 0x2D-3A: -./0123456789:
-- 0x3C-5B: <=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[
-- 0x5D-7E: ]^_`abcdefghijklmnopqrstuvwxyz{|}~
note
EIS: "name=valid-characters", "src=http://tools.ietf.org/html/rfc6265#section-4.1.1", "protocol=uri"
once
Result := ("!#$%%&'()*+-./0123456789:<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz{|}~").area
end
is_valid_character (c: CHARACTER): BOOLEAN is_valid_character (c: CHARACTER): BOOLEAN
-- RFC6265 that specifies that the following is valid for characters in cookies. Cookies are also supposed to be double quoted. -- RFC6265 that specifies that the following is valid for characters in cookies.
-- The following character ranges are valid:http://tools.ietf.org/html/rfc6265#section-4.1.1 -- The following character ranges are valid:http://tools.ietf.org/html/rfc6265#section-4.1.1
-- %x21 / %x23-2B / %x2D-3A / %x3C-5B / %x5D-7E -- %x21 / %x23-2B / %x2D-3A / %x3C-5B / %x5D-7E
-- 0x21: ! -- 0x21: !

View File

@@ -325,19 +325,16 @@ feature -- Header add cookie
--| the same response with the same cookie-name. --| the same response with the same cookie-name.
local local
l_same_cookie_name: BOOLEAN l_same_cookie_name: BOOLEAN
l_cookie_header: STRING
l_cn: STRING
l_nv: STRING l_nv: STRING
do do
across internal_header.headers as ic until l_same_cookie_name loop across
internal_header.headers as ic
until l_same_cookie_name
loop
if ic.item.starts_with ("Set-Cookie") then if ic.item.starts_with ("Set-Cookie") then
l_cookie_header := ic.item.twin l_nv := ic.item.split (';').at (1).split (':').at (2)
l_cookie_header.to_lower
l_cn := a_cookie.name
l_cn.to_lower
l_nv := l_cookie_header.split (';').at (1).split (':').at (2)
l_nv.adjust l_nv.adjust
if l_nv.starts_with (l_cn) then if l_nv.starts_with (a_cookie.name) then
l_same_cookie_name := True l_same_cookie_name := True
end end
end end

View File

@@ -1,5 +1,9 @@
note note
description: "Summary description for {WGI_RESPONSE_NULL}." description: "[
Mock implementation of the WGI_RESPONSE interface.
Used for testing the ewf core and also web applications.
]"
date: "$Date$" date: "$Date$"
revision: "$Revision$" revision: "$Revision$"

View File

@@ -1,6 +1,9 @@
note note
description: "Summary description for {WSF_SERVICE_NULL}." description: "[
author: "" Mock implementation of the WGI_SERVICE interface.
Used for testing the ewf core and also web applications
]"
date: "$Date$" date: "$Date$"
revision: "$Revision$" revision: "$Revision$"