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
description: "[
This class represents the value of a HTTP cookie, transferred in a request.
The class has features to build an HTTP cookie.
This class represents the value of a HTTP cookie, transferred in a request.
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
* 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.
Domain
* 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.
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 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
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 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
HttpOnly, Secure
* Note that the HttpOnly attribute is independent of the Secure attribute: a cookie can have both the HttpOnly and the Secure attribute.
HttpOnly, Secure
* Note that the HttpOnly attribute is independent of the Secure attribute: a cookie can have both the HttpOnly and the Secure attribute.
]"
date: "$Date$"
@@ -32,7 +32,10 @@ feature {NONE} -- Initialization
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'.
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
set_name (a_name)
set_value(a_value)
@@ -66,33 +69,33 @@ feature -- Access
secure: BOOLEAN
-- Value of the Secure attribute.
-- 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
-- Value of the http_only attribute.
-- By default false.
--| Limits the scope of the cookie to HTTP requests.
--| Limits the scope of the cookie to HTTP requests.
max_age: INTEGER
-- 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.
--| 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?
local
l_iterator: STRING_ITERATION_CURSOR
l_found: BOOLEAN
do
create l_iterator.make (a_name)
Result := True
across
l_iterator as ic
until
l_found
loop
if is_valid_character (ic.item.to_character_8) then
if not is_valid_character (ic.item.to_character_8) then
Result := False
l_found := True
end
@@ -100,37 +103,43 @@ feature -- Access
end
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.
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.
feature -- Change Element
set_name (a_name: READABLE_STRING_GENERAL)
set_name (a_name: READABLE_STRING_8)
-- 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
name := a_name.as_string_8
name := a_name
ensure
name_set: name = a_name
end
set_value (a_value: READABLE_STRING_GENERAL)
set_value (a_value: READABLE_STRING_8)
-- 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
value := a_value.as_string_8
value := a_value
ensure
value_set: value = a_value
end
set_expiration (a_date: READABLE_STRING_GENERAL)
set_expiration (a_date: READABLE_STRING_8)
-- Set `expiration' with `a_date'
do
expiration := a_date.as_string_32
expiration := a_date
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
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))
end
set_path (a_path: READABLE_STRING_GENERAL)
set_path (a_path: READABLE_STRING_8)
-- Set `path' with `a_path'
do
path := a_path.as_string_8
path := a_path
ensure
path_set: path = a_path
end
set_domain (a_domain: READABLE_STRING_GENERAL)
set_domain (a_domain: READABLE_STRING_8)
-- Set `domain' with `a_domain'
-- Note: you should avoid using "localhost" as `domain' for local cookies
-- since they are not always handled by browser (for instance Chrome)
require
domain_without_port_info: a_domain /= Void implies a_domain.index_of (':', 1) = 0
do
domain := a_domain.as_string_8
domain := a_domain
ensure
domain_set: domain = a_domain
end
@@ -218,11 +227,11 @@ feature -- Change Element
include_expires := False
include_max_age := False
ensure
expires_false: not include_expires
max_age_false: not include_max_age
expires_false: not include_expires
max_age_false: not include_max_age
end
feature -- Date Utils
feature {NONE} -- Date Utils
date_to_rfc1123_http_date_format (dt: DATE_TIME): STRING_8
-- String representation of `dt' using the RFC 1123
@@ -236,7 +245,7 @@ feature -- Date Utils
feature -- Output
header_line: STRING
-- String representation of Set-Cookie header of current.
-- String representation of Set-Cookie header line of Current.
local
s: STRING
do
@@ -260,17 +269,21 @@ feature -- Output
-- Max-Age
elseif include_max_age then
s.append ("; Max-Age=")
s.append (max_age.out)
s.append_integer (max_age)
else
-- 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
s.append ("; Expires=")
s.append (l_expires)
end
s.append ("; Max-Age=")
s.append (max_age.out)
s.append_integer (max_age)
end
if secure then
@@ -291,24 +304,8 @@ feature {NONE} -- Constants
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
-- 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
-- %x21 / %x23-2B / %x2D-3A / %x3C-5B / %x5D-7E
-- 0x21: !