diff --git a/library/server/wsf/src/wsf_request.e b/library/server/wsf/src/wsf_request.e index b3a54d86..a38ef61d 100644 --- a/library/server/wsf/src/wsf_request.e +++ b/library/server/wsf/src/wsf_request.e @@ -1227,19 +1227,19 @@ feature -- HTTP_* do Result := wgi_request.http_range end - + http_content_range: detachable READABLE_STRING_8 -- Partial range of selected representation enclosed in message payload do Result := wgi_request.http_content_range end - + http_content_encoding: detachable READABLE_STRING_8 -- Encoding (usually compression) of message payload do Result := wgi_request.http_content_encoding end - + feature -- Extra CGI environment variables request_uri: READABLE_STRING_8 @@ -1317,7 +1317,20 @@ feature {NONE} -- Cookies p < 1 loop i := s.index_of ('=', p) - if i > 0 then + if i = 0 then + i := s.index_of (';', p) + if i = 0 then + -- name without value, let's consider as empty value. + --| name=value; foo + k := s.substring (p, n) + p := 0 -- force termination + else + -- name without value, let's consider as empty value. + k := s.substring (p, i - 1) + p := i + 1 --| name=value; foo ; name2=value2 + end + create v.make_empty + else j := s.index_of (';', i) if j = 0 then j := n + 1 @@ -1329,9 +1342,14 @@ feature {NONE} -- Cookies k := s.substring (p, i - 1) v := s.substring (i + 1, j - 1) p := j + 1 + if p > n then + p := 0 -- force termination + end end - k.left_adjust - k.right_adjust + end + k.left_adjust + k.right_adjust + if not k.is_empty then add_value_to_table (k, v, l_cookies) end end diff --git a/library/server/wsf/tests/src/test_wsf_cookies.e b/library/server/wsf/tests/src/test_wsf_cookies.e new file mode 100644 index 00000000..e5a7c38f --- /dev/null +++ b/library/server/wsf/tests/src/test_wsf_cookies.e @@ -0,0 +1,92 @@ +note + description: "[ + Eiffel tests that can be executed by testing tool. + ]" + author: "EiffelStudio test wizard" + date: "$Date$" + revision: "$Revision$" + testing: "type/manual" + +class + TEST_WSF_COOKIES + +inherit + EQA_TEST_SET + + WSF_SERVICE + undefine + default_create + end + +feature {NONE} -- Events + + port_number: INTEGER + base_url: detachable STRING + +feature -- Execution + + execute (req: WSF_REQUEST; res: WSF_RESPONSE) + do + --| do nothing + end + +feature -- Tests + + test_cookies + local + req: WSF_REQUEST + do + --| Case #1 + req := new_request (<< + ["REQUEST_METHOD", "GET"], + ["QUERY_STRING", ""], + ["REQUEST_URI", "/cookie"], + ["HTTP_COOKIE", "name=value; name2=value2"] + >> + ) + assert ("#1 cookie name", attached {WSF_STRING} req.cookie ("name") as v and then v.value.is_case_insensitive_equal ("value")) + assert ("#1 cookie name2", attached {WSF_STRING} req.cookie ("name2") as v and then v.value.is_case_insensitive_equal ("value2")) + + req := new_request (<< + ["REQUEST_METHOD", "GET"], + ["QUERY_STRING", ""], + ["REQUEST_URI", "/cookie"], + ["HTTP_COOKIE", "name=value"] + >> + ) + assert ("#2 cookie name", attached {WSF_STRING} req.cookie ("name") as v and then v.value.is_case_insensitive_equal ("value")) + + req := new_request (<< + ["REQUEST_METHOD", "GET"], + ["QUERY_STRING", ""], + ["REQUEST_URI", "/cookie"], + ["HTTP_COOKIE", "name=value;"] + >> + ) + assert ("#3 cookie name", attached {WSF_STRING} req.cookie ("name") as v and then v.value.is_case_insensitive_equal ("value")) + + req := new_request (<< + ["REQUEST_METHOD", "GET"], + ["QUERY_STRING", ""], + ["REQUEST_URI", "/cookie"], + ["HTTP_COOKIE", "name1=value1; namewithoutvalue"] + >> + ) + assert ("#4 cookie name1", attached {WSF_STRING} req.cookie ("name1") as v and then v.value.is_case_insensitive_equal ("value1")) + assert ("#4 cookie namewithoutvalue", attached {WSF_STRING} req.cookie ("namewithoutvalue") as v and then v.value.is_empty) + + end + +feature {NONE} -- Implementation + + new_request (a_meta: ARRAY [TUPLE [name: READABLE_STRING_8; value: READABLE_STRING_8]]): WSF_REQUEST_NULL + local + wgi_req: WGI_REQUEST + do + create {WGI_REQUEST_NULL} wgi_req.make_with_file (a_meta, io.input) + create Result.make_from_wgi (wgi_req) + end + +end + +