33 This class represents the value of a HTTP cookie, transferred in a request.
44 The class has features to build an HTTP cookie.
55
6- Following a newer RFC standard for Cookies RCF6265.
6+ Following a newer RFC standard for Cookies http://tools.ietf.org/html/rfc6265
77
88 Domain
99 * WARNING: Some existing user agents treat an absent Domain attribute as if the Domain attribute were present and contained the current host name.
2020]"
2121 date : " $Date$"
2222 revision : " $Revision$"
23- EIS : " name=HTTP Cookie specification" , " src=https ://httpwg.github.io/specs /rfc6265.html " , " protocol=uri"
23+ EIS : " name=HTTP Cookie specification" , " src=http ://tools.ietf.org/html /rfc6265" , " protocol=uri"
2424class
2525 HTTP_COOKIE
2626
2929
3030feature {NONE } -- Initialization
3131
32- make (a_name : READABLE_STRING_ 32 ; a_value : READABLE_STRING_ 32 )
32+ make (a_name : READABLE_STRING_ 8 ; a_value : READABLE_STRING_ 8 )
3333 -- Create an object instance of cookie with name `a_name' and value `a_value'.
3434 require
3535 make_sense : (a_name /= Void and a_value /= Void ) and then (not a_name .is_empty and not a_value .is_empty )
@@ -45,21 +45,21 @@ feature {NONE} -- Initialization
4545
4646feature -- Access
4747
48- name : STRING_ 32
48+ name : STRING_ 8
4949 -- name of the cookie.
5050
51- value : STRING_ 32
51+ value : STRING_ 8
5252 -- value of the cookie.
5353
54- expiration : detachable STRING
54+ expiration : detachable STRING_ 8
5555 -- Value of the Expires attribute.
5656
57- path : detachable STRING_ 32
57+ path : detachable STRING_ 8
5858 -- Value of the Path attribute.
5959 -- Path to which the cookie applies.
6060 -- | The path "/", specify a cookie that apply to all URLs in your site.
6161
62- domain : detachable STRING_ 32
62+ domain : detachable STRING_ 8
6363 -- Value of the Domain attribute.
6464 -- Domain to which the cookies apply.
6565
@@ -79,23 +79,22 @@ feature -- Access
7979 -- | By default max_age < 0 indicate a cookie will last only for the current user-agent (Browser, etc) session.
8080 -- | A value of 0 instructs the user-agent to delete the cookie.
8181
82- has_valid_characters (a_name : READABLE_STRING_ 32 ):BOOLEAN
82+ has_valid_characters (a_name : READABLE_STRING_GENERAL ):BOOLEAN
8383 -- Has `a_name' valid characters for cookies?
8484 local
8585 l_iterator : STRING_ITERATION_CURSOR
8686 l_found : BOOLEAN
8787 do
8888 create l_iterator .make (a_name )
89- from
90- l_iterator .start
89+
90+ across
91+ l_iterator as ic
9192 until
92- l_iterator . after or l_found
93+ l_found
9394 loop
94- if valid_characters . index_of ( l_iterator .item .to_character_ 8 , 0 ) = - 1 then
95+ if is_valid_character ( ic .item .to_character_ 8 ) then
9596 Result := False
9697 l_found := True
97- else
98- l_iterator .forth
9998 end
10099 end
101100 end
@@ -110,28 +109,28 @@ feature -- Access
110109
111110feature -- Change Element
112111
113- set_name (a_name : READABLE_STRING_ 32 )
112+ set_name (a_name : READABLE_STRING_GENERAL )
114113 -- Set `name' with `a_name'.
115114 do
116- name := a_name
115+ name := a_name . as_string_ 8
117116 ensure
118117 name_set : name = a_name
119118 end
120119
121- set_value (a_value : READABLE_STRING_ 32 )
120+ set_value (a_value : READABLE_STRING_GENERAL )
122121 -- Set `value' with `a_value'.
123122 do
124- value := a_value
123+ value := a_value . as_string_ 8
125124 ensure
126125 value_set : value = a_value
127126 end
128127
129- set_expiration (a_date : READABLE_STRING_ 32 )
128+ set_expiration (a_date : READABLE_STRING_GENERAL )
130129 -- Set `expiration' with `a_date'
131130 do
132- expiration := a_date
131+ expiration := a_date . as_string_ 32
133132 ensure
134- expiration_set : attached expiration as l_expiration and then l_expiration .same_string (a_date )
133+ expiration_set : attached expiration as l_expiration and then l_expiration .same_string (a_date . as_string_ 8 )
135134 end
136135
137136 set_expiration_date (a_date : DATE_TIME )
@@ -142,22 +141,22 @@ feature -- Change Element
142141 expiration_set : attached expiration as l_expiration and then l_expiration .same_string (date_to_rfc 1123 _http_date_format (a_date ))
143142 end
144143
145- set_path (a_path : READABLE_STRING_ 32 )
144+ set_path (a_path : READABLE_STRING_GENERAL )
146145 -- Set `path' with `a_path'
147146 do
148- path := a_path
147+ path := a_path . as_string_ 8
149148 ensure
150149 path_set : path = a_path
151150 end
152151
153- set_domain (a_domain : READABLE_STRING_ 32 )
152+ set_domain (a_domain : READABLE_STRING_GENERAL )
154153 -- Set `domain' with `a_domain'
155154 -- Note: you should avoid using "localhost" as `domain' for local cookies
156155 -- since they are not always handled by browser (for instance Chrome)
157156 require
158157 domain_without_port_info : a_domain /= Void implies a_domain .index_of (':', 1 ) = 0
159158 do
160- domain := a_domain
159+ domain := a_domain . as_string_ 8
161160 ensure
162161 domain_set : domain = a_domain
163162 end
@@ -236,7 +235,7 @@ feature -- Date Utils
236235
237236feature -- Output
238237
239- cookie_header : STRING
238+ header_line : STRING
240239 -- String representation of Set-Cookie header of current.
241240 local
242241 s : STRING
@@ -307,6 +306,31 @@ feature {NONE} -- Constants
307306 Result := (" !#$%%&'()*+-./0123456789:<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz{|}~" ).area
308307 end
309308
309+
310+ is_valid_character (c : CHARACTER ): BOOLEAN
311+ -- RFC6265 that specifies that the following is valid for characters in cookies. Cookies are also supposed to be double quoted.
312+ -- The following character ranges are valid:http://tools.ietf.org/html/rfc6265#section-4.1.1
313+ -- %x21 / %x23-2B / %x2D-3A / %x3C-5B / %x5D-7E
314+ -- 0x21: !
315+ -- 0x23-2B: #$%&'()*+
316+ -- 0x2D-3A: -./0123456789:
317+ -- 0x3C-5B: <=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[
318+ -- 0x5D-7E: ]^_`abcdefghijklmnopqrstuvwxyz{|}~
319+ note
320+ EIS : " name=valid-characters" , " src=http://tools.ietf.org/html/rfc6265#section-4.1.1" , " protocol=uri"
321+ do
322+ Result := True
323+ inspect c .natural_ 32 _code
324+ when 0 x 21 then
325+ when 0 x 23 .. 0 x 2 B then
326+ when 0 x 2 D .. 0 x 3 A then
327+ when 0 x 3 C .. 0 x 5 B then
328+ when 0 x 5 D .. 0 x 7 E then
329+ else
330+ Result := False
331+ end
332+ end
333+
310334note
311335 copyright : " 2011-2015, Jocelyn Fiat, Eiffel Software and others"
312336 license : " Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
0 commit comments