From f8a0bbf88bc04cfa38681bab7302dd8b851275f8 Mon Sep 17 00:00:00 2001 From: Jocelyn Fiat Date: Mon, 16 Sep 2013 16:24:05 +0200 Subject: [PATCH] Added autotests to http library in relation with mime type and content type. Fixed an issue with more than one parameter. --- .../protocol/http/src/http_content_type.e | 3 +- .../protocol/http/src/http_media_type.e | 25 ++- .../http/tests/http_content_type_set.e | 203 ++++++++++++++++++ 3 files changed, 221 insertions(+), 10 deletions(-) create mode 100644 library/network/protocol/http/tests/http_content_type_set.e diff --git a/library/network/protocol/http/src/http_content_type.e b/library/network/protocol/http/src/http_content_type.e index 0a819aac..b159ddc7 100644 --- a/library/network/protocol/http/src/http_content_type.e +++ b/library/network/protocol/http/src/http_content_type.e @@ -4,6 +4,7 @@ note ]" date: "$Date$" revision: "$Revision$" + EIS: "name=RFC3875", "protocol=URI", "src=http://tools.ietf.org/html/rfc3875" class HTTP_CONTENT_TYPE @@ -34,7 +35,7 @@ feature -- Constant charset_parameter_name: STRING_8 = "charset" note - copyright: "2011-2012, Jocelyn Fiat, Eiffel Software and others" + copyright: "2011-2013, Jocelyn Fiat, Eiffel Software and others" license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)" source: "[ Eiffel Software diff --git a/library/network/protocol/http/src/http_media_type.e b/library/network/protocol/http/src/http_media_type.e index 0b9d0055..0a2a11b6 100644 --- a/library/network/protocol/http/src/http_media_type.e +++ b/library/network/protocol/http/src/http_media_type.e @@ -2,7 +2,7 @@ note description: "[ This class is to represent a media type - the Internet Media Type [9] of the attached entity if the type + the Internet Media Type of the attached entity if the type was provided via a "Content-type" field in the wgi_request header, or if the server can determine it in the absence of a supplied "Content-type" field. The syntax is the same as for the HTTP @@ -29,6 +29,8 @@ note ]" date: "$Date$" revision: "$Revision$" + EIS: "name=Wikipedia/Media Type", "protocol=URI", "src=http://en.wikipedia.org/wiki/Internet_media_type" + EIS: "name=RFC2046", "protocol=URI", "src=http://tools.ietf.org/html/rfc2046" class HTTP_MEDIA_TYPE @@ -76,14 +78,19 @@ feature {NONE} -- Initialization p := s.index_of (';', i) if p > 0 then t := s.substring (i, p - 1) - i := p + 1 - p := s.index_of (';', i) - if p = 0 then - add_parameter_from_string (s, i, n) - i := n - else - add_parameter_from_string (s, i, p - 1) + from + until + i >= n + loop i := p + 1 + p := s.index_of (';', i) + if p = 0 then + add_parameter_from_string (s, i, n) + i := n + else + add_parameter_from_string (s, i, p - 1) + i := p + 1 + end end else t := s.substring (i, n) @@ -334,7 +341,7 @@ invariant type_and_subtype_not_empty: not has_error implies not type.is_empty and not subtype.is_empty note - copyright: "2011-2012, Jocelyn Fiat, Eiffel Software and others" + copyright: "2011-2013, Jocelyn Fiat, Eiffel Software and others" license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)" source: "[ Eiffel Software diff --git a/library/network/protocol/http/tests/http_content_type_set.e b/library/network/protocol/http/tests/http_content_type_set.e new file mode 100644 index 00000000..3222c967 --- /dev/null +++ b/library/network/protocol/http/tests/http_content_type_set.e @@ -0,0 +1,203 @@ +note + description : "Objects that ..." + author : "$Author$" + date : "$Date$" + revision : "$Revision$" + +class + HTTP_CONTENT_TYPE_SET + +inherit + EQA_TEST_SET + +feature -- Content type + + test_http_content_type + local + ct: HTTP_CONTENT_TYPE + do + test_content_type ("application/atom+xml", "application", "atom+xml") -- Atom feeds + test_content_type ("application/ecmascript", "application", "ecmascript") -- ECMAScript/JavaScript; Defined in RFC 4329 (equivalent to application/javascript but with stricter processing rules) + test_content_type ("application/EDI-X12", "application", "EDI-X12") -- EDI X12 data; Defined in RFC 1767 + test_content_type ("application/EDIFACT", "application", "EDIFACT") -- EDI EDIFACT data; Defined in RFC 1767 + test_content_type ("application/json", "application", "json") -- JavaScript Object Notation JSON; Defined in RFC 4627 + test_content_type ("application/javascript", "application", "javascript") -- ECMAScript/JavaScript; Defined in RFC 4329 (equivalent to application/ecmascript but with looser processing rules) It is not accepted in IE 8 or earlier - text/javascript is accepted but it is defined as obsolete in RFC 4329. The "type" attribute of the