Renamed content_negotation' as content_negotiation' (fixed typo)
Updated .ecf and Eiffel code depending on previous CONNEG
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
note
|
||||
description : "eMIME application root class"
|
||||
date : "$Date$"
|
||||
revision : "$Revision$"
|
||||
|
||||
class
|
||||
APPLICATION
|
||||
|
||||
inherit
|
||||
ARGUMENTS
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make
|
||||
local
|
||||
mime_parse : MIME_PARSE
|
||||
accept : STRING
|
||||
charset_parse : COMMON_ACCEPT_HEADER_PARSER
|
||||
language : LANGUAGE_PARSE
|
||||
do
|
||||
create mime_parse
|
||||
-- parse_result := mime_parse.parse_mime_type ("application/xhtml;q=0.5")
|
||||
-- print ("%N"+parse_result.out)
|
||||
|
||||
-- parse_result := mime_parse.parse_media_range ("application/xml;q=1")
|
||||
-- print ("%N"+parse_result.out)
|
||||
-- check
|
||||
-- "('application', 'xml', {'q':'1',})" ~ mime_parse.parse_media_range ("application/xml;q=1").out
|
||||
-- end
|
||||
|
||||
-- parse_result := mime_parse.parse_media_range ("application/xml")
|
||||
-- print ("%N"+parse_result.out)
|
||||
-- check
|
||||
-- "('application', 'xml', {'q':'1',})" ~ mime_parse.parse_media_range ("application/xml;q=1").out
|
||||
-- end
|
||||
-- assertEquals("('application', 'xml', {'q':'1',})", MIMEParse
|
||||
-- .parseMediaRange("application/xml").toString());
|
||||
-- assertEquals("('application', 'xml', {'q':'1',})", MIMEParse
|
||||
-- .parseMediaRange("application/xml;q=").toString());
|
||||
-- assertEquals("('application', 'xml', {'q':'1',})", MIMEParse
|
||||
-- .parseMediaRange("application/xml ; q=").toString());
|
||||
-- assertEquals("('application', 'xml', {'b':'other','q':'1',})",
|
||||
-- MIMEParse.parseMediaRange("application/xml ; q=1;b=other")
|
||||
-- .toString());
|
||||
-- assertEquals("('application', 'xml', {'b':'other','q':'1',})",
|
||||
-- MIMEParse.parseMediaRange("application/xml ; q=2;b=other")
|
||||
-- .toString());
|
||||
-- // Java URLConnection class sends an Accept header that includes a
|
||||
-- // single *
|
||||
-- assertEquals("('*', '*', {'q':'.2',})", MIMEParse.parseMediaRange(
|
||||
-- " *; q=.2").toString());
|
||||
|
||||
accept := "application/atom+xml;q=1.0,application/xml;q=0.6,text/html"
|
||||
print ("%N"+mime_parse.quality ("text/html;q=1.0", accept).out)
|
||||
print ("%N"+mime_parse.quality ("application/xml", accept).out)
|
||||
print ("%N"+mime_parse.quality ("*/*;q=0.1", accept).out)
|
||||
|
||||
accept := "application/atom+xml"
|
||||
print ("%N"+mime_parse.parse_mime_type (accept).out)
|
||||
create charset_parse
|
||||
accept := "iso-8859-5"
|
||||
print ("%N" + charset_parse.parse_common (accept).out)
|
||||
accept := "unicode-1-1;q=0.8"
|
||||
print ("%N" + charset_parse.parse_common (accept).out)
|
||||
|
||||
|
||||
accept:= "iso-8859-5, unicode-1-1;q=0.8"
|
||||
print ("%N"+ charset_parse.quality ("iso-8859-5", accept).out)
|
||||
print ("%N"+ charset_parse.quality ("unicode-1-1", accept).out)
|
||||
print ("%N"+ charset_parse.quality ("iso-8859-1", accept).out)
|
||||
|
||||
|
||||
create language
|
||||
accept :="da, en-gb;q=0.8, en;q=0.7"
|
||||
print (language.best_match (accept.split (','), "da"))
|
||||
print (language.best_match (accept.split (','), "en-*"))
|
||||
|
||||
print ("%N"+language.parse_language_range ("da").out)
|
||||
print ("%N"+language.parse_language_range ("en-gb;q=0.8").out)
|
||||
print ("%N"+language.parse_language_range ("en;q=0.7").out)
|
||||
print ("%N"+language.parse_language_range ("en-*").out)
|
||||
end
|
||||
|
||||
end
|
||||
@@ -0,0 +1,57 @@
|
||||
note
|
||||
description: "Summary description for {COMMON_ACCEPT_HEADER_PARSER_TEST}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
COMMON_ACCEPT_HEADER_PARSER_TEST
|
||||
|
||||
inherit
|
||||
EQA_TEST_SET
|
||||
redefine
|
||||
on_prepare
|
||||
end
|
||||
|
||||
feature {NONE} -- Events
|
||||
|
||||
on_prepare
|
||||
-- Called after all initializations in `default_create'.
|
||||
do
|
||||
create parser
|
||||
end
|
||||
|
||||
feature -- Test routines
|
||||
|
||||
test_parse_charsets
|
||||
do
|
||||
assert ("Expected ('iso-8859-5', {'q':'1.0',})", parser.parse_common("iso-8859-5").out.same_string("('iso-8859-5', {'q':'1.0',})") )
|
||||
assert ("Expected ('unicode-1-1', {'q':'0.8',})", parser.parse_common("unicode-1-1;q=0.8").out.same_string("('unicode-1-1', {'q':'0.8',})") )
|
||||
assert ("Expected ('*', {'q':'1.0',})", parser.parse_common("*").out.same_string("('*', {'q':'1.0',})") )
|
||||
end
|
||||
|
||||
|
||||
test_quality_example
|
||||
local
|
||||
accept : STRING
|
||||
do
|
||||
accept := "iso-8859-5, unicode-1-1;q=0.8";
|
||||
assert ("Expected 1.0", 1.0 = parser.quality ("iso-8859-5", accept))
|
||||
assert ("Expected 0.8", 0.8 = parser.quality ("unicode-1-1", accept))
|
||||
end
|
||||
|
||||
|
||||
test_best_match
|
||||
local
|
||||
charset_supported : LIST [STRING]
|
||||
l_charsets : STRING
|
||||
do
|
||||
l_charsets := "iso-8859-5, unicode-1-1;q=0.8"
|
||||
charset_supported := l_charsets.split(',')
|
||||
assert ("Expected iso-8859-5", parser.best_match (charset_supported, "*").same_string ("iso-8859-5"))
|
||||
assert ("Expected unicode-1-1", parser.best_match (charset_supported, "unicode-1-1;q=1").same_string ("unicode-1-1"))
|
||||
end
|
||||
|
||||
parser : COMMON_ACCEPT_HEADER_PARSER
|
||||
|
||||
end
|
||||
@@ -0,0 +1,167 @@
|
||||
note
|
||||
description: "Summary description for {CONNEG_SERVER_SIDE_TEST}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
CONNEG_SERVER_SIDE_TEST
|
||||
inherit
|
||||
EQA_TEST_SET
|
||||
redefine
|
||||
on_prepare
|
||||
end
|
||||
|
||||
feature {NONE} -- Events
|
||||
|
||||
on_prepare
|
||||
-- Called after all initializations in `default_create'.
|
||||
do
|
||||
create conneg.make ("application/json", "es", "UTF-8", "")
|
||||
-- set default values
|
||||
end
|
||||
|
||||
feature -- Test routines
|
||||
test_media_type_negotiation
|
||||
local
|
||||
media_variants : MEDIA_TYPE_VARIANT_RESULTS
|
||||
mime_types_supported : LIST [STRING]
|
||||
l_types : STRING
|
||||
do
|
||||
-- Scenario 1, the server side does not support client preferences
|
||||
l_types := "application/json,application/xbel+xml,application/xml"
|
||||
mime_types_supported := l_types.split(',')
|
||||
media_variants := conneg.media_type_preference (mime_types_supported, "text/html")
|
||||
assert ("Expected Not Acceptable", not media_variants.is_acceptable)
|
||||
assert ("Same Value at 1",mime_types_supported.at (1).is_equal (media_variants.supported_variants.at (1)))
|
||||
assert ("Same count",mime_types_supported.count = media_variants.supported_variants.count)
|
||||
assert ("Variant header is void",media_variants.variant_header = Void)
|
||||
assert ("Media type is void",media_variants.type = Void)
|
||||
|
||||
-- Scenario 2, the client doesnt send values in the header, Accept:
|
||||
media_variants := conneg.media_type_preference (mime_types_supported, "")
|
||||
assert ("Expected Acceptable", media_variants.is_acceptable)
|
||||
assert ("Variants is dettached",media_variants.supported_variants = Void)
|
||||
assert ("Mime is defaul", conneg.mime_default.is_equal (media_variants.type))
|
||||
assert ("Variant header", media_variants.variant_header = Void)
|
||||
|
||||
--Scenario 3, the server select the best match, and set the vary header
|
||||
media_variants := conneg.media_type_preference (mime_types_supported, "text/*,application/json;q=0.5")
|
||||
assert ("Expected Acceptable", media_variants.is_acceptable)
|
||||
assert ("Variants is dettached",media_variants.supported_variants = Void)
|
||||
assert ("Variant Header", media_variants.variant_header.is_equal ("Accept"))
|
||||
assert ("Media Type is application/json", media_variants.type.is_equal ("application/json"))
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
test_charset_negotiation
|
||||
local
|
||||
charset_variants : CHARACTER_ENCODING_VARIANT_RESULTS
|
||||
charset_supported : LIST [STRING]
|
||||
l_charset : STRING
|
||||
do
|
||||
-- Scenario 1, the server side does not support client preferences
|
||||
l_charset := "UTF-8, iso-8859-5"
|
||||
charset_supported := l_charset.split(',')
|
||||
charset_variants := conneg.charset_preference (charset_supported, "unicode-1-1")
|
||||
assert ("Expected Not Acceptable", not charset_variants.is_acceptable)
|
||||
assert ("Same Value at 1",charset_supported.at (1).is_equal (charset_variants.supported_variants.at (1)))
|
||||
assert ("Same count",charset_supported.count = charset_variants.supported_variants.count)
|
||||
assert ("Variant header is void",charset_variants.variant_header = Void)
|
||||
assert ("Character type is void",charset_variants.type = Void)
|
||||
|
||||
|
||||
-- Scenario 2, the client doesnt send values in the header, Accept-Charset:
|
||||
charset_variants := conneg.charset_preference (charset_supported, "")
|
||||
assert ("Expected Acceptable", charset_variants.is_acceptable)
|
||||
assert ("Variants is dettached",charset_variants.supported_variants = Void)
|
||||
assert ("Charset is defaul", conneg.charset_default.is_equal (charset_variants.type))
|
||||
assert ("Variant header", charset_variants.variant_header = Void)
|
||||
|
||||
|
||||
--Scenario 3, the server select the best match, and set the vary header
|
||||
charset_variants := conneg.charset_preference (charset_supported, "unicode-1-1, UTF-8;q=0.3, iso-8859-5")
|
||||
assert ("Expected Acceptable", charset_variants.is_acceptable)
|
||||
assert ("Variants is dettached",charset_variants.supported_variants = Void)
|
||||
assert ("Variant Header", charset_variants.variant_header.is_equal ("Accept-Charset"))
|
||||
assert ("Character Type is iso-8859-5", charset_variants.type.is_equal ("iso-8859-5"))
|
||||
end
|
||||
|
||||
test_compression_negotiation
|
||||
local
|
||||
compression_variants : COMPRESSION_VARIANT_RESULTS
|
||||
compression_supported : LIST [STRING]
|
||||
l_compression : STRING
|
||||
do
|
||||
-- Scenario 1, the server side does not support client preferences
|
||||
l_compression := ""
|
||||
compression_supported := l_compression.split(',')
|
||||
compression_variants := conneg.encoding_preference (compression_supported, "gzip")
|
||||
assert ("Expected Not Acceptable", not compression_variants.is_acceptable)
|
||||
assert ("Same Value at 1",compression_supported.at (1).is_equal (compression_variants.supported_variants.at (1)))
|
||||
assert ("Same count",compression_supported.count = compression_variants.supported_variants.count)
|
||||
assert ("Variant header is void",compression_variants.variant_header = Void)
|
||||
assert ("Compression type is void",compression_variants.type = Void)
|
||||
|
||||
|
||||
-- Scenario 2, the client doesnt send values in the header, Accept-Encoding
|
||||
compression_variants := conneg.encoding_preference (compression_supported, "")
|
||||
assert ("Expected Acceptable", compression_variants.is_acceptable)
|
||||
assert ("Variants is dettached",compression_variants.supported_variants = Void)
|
||||
assert ("Compression is defaul", conneg.encoding_default.is_equal (compression_variants.type))
|
||||
assert ("Variant header", compression_variants.variant_header = Void)
|
||||
|
||||
|
||||
--Scenario 3, the server select the best match, and set the vary header
|
||||
l_compression := "gzip"
|
||||
compression_supported := l_compression.split(',')
|
||||
conneg.set_encoding_default("gzip")
|
||||
compression_variants := conneg.encoding_preference (compression_supported, "compress,gzip;q=0.7")
|
||||
assert ("Expected Acceptable", compression_variants.is_acceptable)
|
||||
assert ("Variants is dettached",compression_variants.supported_variants = Void)
|
||||
assert ("Variant Header", compression_variants.variant_header.is_equal ("Accept-Encoding"))
|
||||
assert ("Encoding Type is gzip", compression_variants.type.is_equal ("gzip"))
|
||||
end
|
||||
|
||||
|
||||
|
||||
test_language_negotiation
|
||||
local
|
||||
language_variants : LANGUAGE_VARIANT_RESULTS
|
||||
languages_supported : LIST [STRING]
|
||||
l_languages : STRING
|
||||
do
|
||||
-- Scenario 1, the server side does not support client preferences
|
||||
l_languages := "es,en,en-US,fr;q=0.6"
|
||||
languages_supported := l_languages.split(',')
|
||||
language_variants := conneg.language_preference (languages_supported, "de")
|
||||
assert ("Expected Not Acceptable", not language_variants.is_acceptable)
|
||||
assert ("Same Value at 1",languages_supported.at (1).is_equal (language_variants.supported_variants.at (1)))
|
||||
assert ("Same count",languages_supported.count = language_variants.supported_variants.count)
|
||||
assert ("Variant header is void",language_variants.variant_header = Void)
|
||||
assert ("Language type is void",language_variants.type = Void)
|
||||
|
||||
|
||||
-- Scenario 2, the client doesnt send values in the header, Accept-Language:
|
||||
language_variants := conneg.language_preference (languages_supported, "")
|
||||
assert ("Expected Acceptable", language_variants.is_acceptable)
|
||||
assert ("Variants is dettached",language_variants.supported_variants = Void)
|
||||
assert ("Language is defaul", conneg.language_default.is_equal (language_variants.type))
|
||||
assert ("Variant header", language_variants.variant_header = Void)
|
||||
|
||||
|
||||
--Scenario 3, the server select the best match, and set the vary header
|
||||
language_variants := conneg.language_preference (languages_supported, "fr,es;q=0.4")
|
||||
assert ("Expected Acceptable", language_variants.is_acceptable)
|
||||
assert ("Variants is dettached",language_variants.supported_variants = Void)
|
||||
assert ("Variant Header", language_variants.variant_header.is_equal ("Accept-Language"))
|
||||
assert ("Language Type is fr", language_variants.type.is_equal ("fr"))
|
||||
|
||||
|
||||
end
|
||||
|
||||
feature -- Implementation
|
||||
conneg : CONNEG_SERVER_SIDE
|
||||
end
|
||||
@@ -0,0 +1,117 @@
|
||||
note
|
||||
description: "Summary description for {LANGUAGE_PARSER_TEST}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
LANGUAGE_PARSER_TEST
|
||||
|
||||
inherit
|
||||
EQA_TEST_SET
|
||||
redefine
|
||||
on_prepare
|
||||
end
|
||||
|
||||
feature {NONE} -- Events
|
||||
|
||||
on_prepare
|
||||
-- Called after all initializations in `default_create'.
|
||||
do
|
||||
create parser
|
||||
end
|
||||
|
||||
feature -- Test routines
|
||||
|
||||
test_parse_media_range
|
||||
do
|
||||
assert ("Expected ('da', {'q':'1.0',})", parser.parse_language_range ("da").out.same_string ("('da', {'q':'1.0',})"));
|
||||
assert ("Expected ('en', 'gb', {'q':'0.8',})", parser.parse_language_range ("en-gb;q=0.8").out.same_string ("('en', 'gb', {'q':'0.8',})"));
|
||||
assert ("Expected ('en', {'q':'0.7',})", parser.parse_language_range ("en;q=0.7").out.same_string ("('en', {'q':'0.7',})"));
|
||||
assert ("Expected ('en', '*', {'q':'1.0',})", parser.parse_language_range ("en-*").out.same_string ("('en', '*', {'q':'1.0',})"));
|
||||
end
|
||||
|
||||
|
||||
test_RFC2616_example
|
||||
local
|
||||
accept : STRING
|
||||
do
|
||||
accept := "da, en-gb;q=0.8, en;q=0.7";
|
||||
assert ("Expected 1.0", 1.0 = parser.quality ("da", accept))
|
||||
assert ("Expected 0.8", 0.8 = parser.quality ("en-gb", accept))
|
||||
assert ("Expected 0.8", 0.8 = parser.quality ("en", accept))
|
||||
assert ("Expected 0.8", 0.8 = parser.quality ("en-*", accept))
|
||||
end
|
||||
|
||||
|
||||
test_best_match
|
||||
local
|
||||
mime_types_supported : LIST [STRING]
|
||||
l_types : STRING
|
||||
do
|
||||
l_types := "en-gb,en-us"
|
||||
mime_types_supported := l_types.split(',')
|
||||
assert ("Expected en-us", parser.best_match (mime_types_supported, "en-us").same_string ("en-us"))
|
||||
assert ("Direct match with a q parameter", parser.best_match (mime_types_supported, "en-gb;q=1").same_string ("en-gb"))
|
||||
assert ("Direct match second choice with a q parameter", parser.best_match (mime_types_supported, "en-us;q=1").same_string ("en-us"))
|
||||
assert ("Direct match using a subtype wildcard", parser.best_match (mime_types_supported, "en-*;q=1").is_equal ("en-gb"))
|
||||
assert ("Match using a type wildcard", parser.best_match (mime_types_supported, "*").same_string ("en-gb"))
|
||||
|
||||
l_types := "en-gb,es"
|
||||
mime_types_supported := l_types.split(',')
|
||||
assert ("Match using a type versus a lower weighted subtype", parser.best_match (mime_types_supported, "es-*;q=0.5,*;q=0.1").same_string ("es"))
|
||||
assert ("Fail to match anything",parser.best_match (mime_types_supported, "fr; q=0.9").same_string (""))
|
||||
|
||||
l_types := "en-gb,en-us"
|
||||
mime_types_supported := l_types.split(',')
|
||||
assert ("Test 1 verify fitness ordering", parser.best_match (mime_types_supported, "en-gb,en-us,*").same_string ("en-gb"))
|
||||
|
||||
l_types := "es,en-gb;q=1.0,fr;q=0.6"
|
||||
mime_types_supported := l_types.split(',')
|
||||
assert ("Match default es at first position", parser.best_match (mime_types_supported, "es;q=1.0,*;q=0.1,fr").same_string ("es"))
|
||||
|
||||
l_types := "en-gb;q=1.0,fr;q=0.6,es"
|
||||
mime_types_supported := l_types.split(',')
|
||||
assert ("Match default es at last position", parser.best_match (mime_types_supported, "es;q=1.0,*;q=0.1,fr").same_string ("es"))
|
||||
|
||||
l_types := "en-gb;q=1.0,fr,es"
|
||||
mime_types_supported := l_types.split(',')
|
||||
assert ("Match first top quality and fitness", parser.best_match (mime_types_supported, "es;q=1.0,*;q=0.1,fr").same_string ("es"))
|
||||
|
||||
l_types := "fr;q=1.0,en,es"
|
||||
mime_types_supported := l_types.split(',')
|
||||
assert ("Test 1", parser.best_match (mime_types_supported, "es;q=1.0,*/*;q=0.1,en;q=0.9").same_string ("es"))
|
||||
|
||||
l_types := "fr;q=1.0,en,es"
|
||||
mime_types_supported := l_types.split(',')
|
||||
assert ("Test 1", parser.best_match (mime_types_supported, "es,*/*;q=0.1,en").same_string ("es"))
|
||||
|
||||
l_types := "fr;q=1.0,en,es"
|
||||
mime_types_supported := l_types.split(',')
|
||||
assert ("Test 2", parser.best_match (mime_types_supported, "en,es,*/*;q=0.1").same_string ("en"))
|
||||
|
||||
l_types := "es,en;q=0.6"
|
||||
mime_types_supported := l_types.split(',')
|
||||
assert ("Test 2", parser.best_match (mime_types_supported, "fr;q=1.0, en;q=0.6, es").same_string ("es"))
|
||||
|
||||
end
|
||||
|
||||
|
||||
test_support_wildcard
|
||||
local
|
||||
mime_types_supported : LIST[STRING]
|
||||
l_types : STRING
|
||||
do
|
||||
l_types := "en-*,fr"
|
||||
mime_types_supported := l_types.split(',')
|
||||
assert ("match using a type wildcard", parser.best_match (mime_types_supported, "en-gb").same_string ("en-*"))
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
parser : LANGUAGE_PARSE
|
||||
|
||||
end
|
||||
|
||||
|
||||
@@ -0,0 +1,155 @@
|
||||
note
|
||||
description: "[
|
||||
Eiffel tests that can be executed by testing tool.
|
||||
]"
|
||||
author: "EiffelStudio test wizard"
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
testing: "type/manual"
|
||||
|
||||
class
|
||||
MIME_PARSER_TEST
|
||||
|
||||
inherit
|
||||
EQA_TEST_SET
|
||||
redefine
|
||||
on_prepare
|
||||
end
|
||||
|
||||
feature {NONE} -- Events
|
||||
|
||||
on_prepare
|
||||
-- Called after all initializations in `default_create'.
|
||||
do
|
||||
create parser
|
||||
end
|
||||
|
||||
feature -- Helper
|
||||
|
||||
format (a_mediatype: HTTP_MEDIA_TYPE): STRING
|
||||
-- Representation of the current object
|
||||
do
|
||||
create Result.make_from_string ("(")
|
||||
if attached a_mediatype.type as t then
|
||||
Result.append_string ("'" + t + "',")
|
||||
end
|
||||
if attached a_mediatype.subtype as st then
|
||||
Result.append_string (" '" + st + "',")
|
||||
end
|
||||
Result.append_string (" {")
|
||||
if attached a_mediatype.parameters as l_params then
|
||||
from
|
||||
l_params.start
|
||||
until
|
||||
l_params.after
|
||||
loop
|
||||
Result.append ("'" + l_params.key_for_iteration + "':'" + l_params.item_for_iteration + "',");
|
||||
l_params.forth
|
||||
end
|
||||
end
|
||||
Result.append ("})")
|
||||
end
|
||||
|
||||
feature -- Test routines
|
||||
|
||||
test_parse_media_range
|
||||
do
|
||||
assert ("Expected ('application', 'xml', {'q':'1',})", format (parser.parse_media_range("application/xml;q=1")).same_string("('application', 'xml', {'q':'1.0',})") )
|
||||
|
||||
assert ("Expected ('application', 'xml', {'q':'1',})", format (parser.parse_media_range("application/xml")).same_string("('application', 'xml', {'q':'1.0',})") )
|
||||
assert ("Expected ('application', 'xml', {'q':'1',})", format (parser.parse_media_range("application/xml;q=")).same_string("('application', 'xml', {'q':'1.0',})") )
|
||||
assert ("Expected ('application', 'xml', {'q':'1',})", format (parser.parse_media_range("application/xml ; q=")).same_string("('application', 'xml', {'q':'1.0',})") )
|
||||
assert ("Expected ('application', 'xml', {'q':'1','b':'other',})", format (parser.parse_media_range("application/xml ; q=1;b=other")).same_string("('application', 'xml', {'q':'1.0','b':'other',})") )
|
||||
assert ("Expected ('application', 'xml', {'q':'1','b':'other',})", format (parser.parse_media_range("application/xml ; q=2;b=other")).same_string("('application', 'xml', {'q':'1.0','b':'other',})") )
|
||||
-- Accept header that includes *
|
||||
assert ("Expected ('*', '*', {'q':'.2',})", format (parser.parse_media_range(" *; q=.2")).same_string("('*', '*', {'q':'.2',})"))
|
||||
end
|
||||
|
||||
|
||||
test_RFC2616_example
|
||||
local
|
||||
accept : STRING
|
||||
do
|
||||
accept := "text/*;q=0.3, text/html;q=0.7, text/html;level=1, text/html;level=2;q=0.4, */*;q=0.5";
|
||||
assert ("Expected 1.0", 1.0 = parser.quality ("text/html;level=1", accept))
|
||||
assert ("Expected 0.3", 0.3 = parser.quality ("text/plain", accept))
|
||||
assert ("Expected 0.7", 0.7 = parser.quality ("text/html", accept))
|
||||
assert ("Expected 0.5", 0.5 = parser.quality ("image/jpeg", accept))
|
||||
assert ("Expected 0.4", 0.4 = parser.quality ("text/html;level=2", accept))
|
||||
assert ("Expected 0.7", 0.7 = parser.quality ("text/html;level=3", accept))
|
||||
end
|
||||
|
||||
|
||||
test_best_match
|
||||
local
|
||||
mime_types_supported : LIST [STRING]
|
||||
l_types : STRING
|
||||
do
|
||||
l_types := "application/xbel+xml,application/xml"
|
||||
mime_types_supported := l_types.split(',')
|
||||
assert ("Expected application/xbel+xml", parser.best_match (mime_types_supported, "application/xbel+xml").same_string ("application/xbel+xml"))
|
||||
assert ("Direct match with a q parameter", parser.best_match (mime_types_supported, "application/xbel+xml;q=1").same_string ("application/xbel+xml"))
|
||||
assert ("Direct match second choice with a q parameter", parser.best_match (mime_types_supported, "application/xml;q=1").same_string ("application/xml"))
|
||||
assert ("Direct match using a subtype wildcard", parser.best_match (mime_types_supported, "application/*;q=1").is_equal ("application/xbel+xml"))
|
||||
assert ("Match using a type wildcard", parser.best_match (mime_types_supported, "*/*").same_string ("application/xbel+xml"))
|
||||
|
||||
l_types := "application/xbel+xml,text/xml"
|
||||
mime_types_supported := l_types.split(',')
|
||||
assert ("Match using a type versus a lower weighted subtype", parser.best_match (mime_types_supported, "text/*;q=0.5,*/*;q=0.1").same_string ("text/xml"))
|
||||
assert ("Fail to match anything",parser.best_match (mime_types_supported, "text/html,application/atom+xml; q=0.9").same_string (""))
|
||||
|
||||
l_types := "application/json,text/html"
|
||||
mime_types_supported := l_types.split(',')
|
||||
assert ("Common Ajax scenario", parser.best_match (mime_types_supported, "application/json,text/javascript, */*").same_string ("application/json"))
|
||||
assert ("Common Ajax scenario,verify fitness ordering", parser.best_match (mime_types_supported, "application/json,text/javascript, */*").same_string ("application/json"))
|
||||
|
||||
l_types := "text/html,application/atom+xml;q=1.0,application/xml;q=0.6"
|
||||
mime_types_supported := l_types.split(',')
|
||||
assert ("Match default text/html at first position", parser.best_match (mime_types_supported, "text/html;q=1.0,*/*;q=0.1,application/xml").same_string ("text/html"))
|
||||
|
||||
l_types := "application/atom+xml;q=1.0,application/xml;q=0.6,text/html"
|
||||
mime_types_supported := l_types.split(',')
|
||||
assert ("Match default text/html at last position", parser.best_match (mime_types_supported, "text/html;q=1.0,*/*;q=0.1,application/xml").same_string ("text/html"))
|
||||
|
||||
l_types := "application/atom+xml;q=1.0,application/xml,text/html"
|
||||
mime_types_supported := l_types.split(',')
|
||||
assert ("Match first top quality and fitness", parser.best_match (mime_types_supported, "text/html;q=1.0,*/*;q=0.1,application/xml").same_string ("text/html"))
|
||||
|
||||
l_types := "application/atom+xml;q=1.0,application/xml,text/html"
|
||||
mime_types_supported := l_types.split(',')
|
||||
assert ("Test 1", parser.best_match (mime_types_supported, "text/html;q=1.0,*/*;q=0.1,application/xml;q=0.9").same_string ("text/html"))
|
||||
|
||||
l_types := "application/atom+xml;q=1.0,application/xml,text/html"
|
||||
mime_types_supported := l_types.split(',')
|
||||
assert ("Test 1", parser.best_match (mime_types_supported, "text/html,*/*;q=0.1,application/xml").same_string ("text/html"))
|
||||
|
||||
l_types := "application/atom+xml;q=1.0,application/xml,text/html"
|
||||
mime_types_supported := l_types.split(',')
|
||||
assert ("Test 2", parser.best_match (mime_types_supported, "application/xml,text/html,*/*;q=0.1").same_string ("application/xml"))
|
||||
|
||||
l_types := "text/html,application/xml;q=0.6"
|
||||
mime_types_supported := l_types.split(',')
|
||||
assert ("Test 2", parser.best_match (mime_types_supported, "application/atom+xml;q=1.0, application/xml;q=0.6, text/html").same_string ("text/html"))
|
||||
|
||||
end
|
||||
|
||||
|
||||
test_support_wildcard
|
||||
local
|
||||
mime_types_supported : LIST[STRING]
|
||||
l_types : STRING
|
||||
do
|
||||
l_types := "image/*,application/xml"
|
||||
mime_types_supported := l_types.split(',')
|
||||
assert ("match using a type wildcard", parser.best_match (mime_types_supported, "image/png").same_string ("image/*"))
|
||||
assert ("match using a wildcard for both requested and supported", parser.best_match (mime_types_supported, "image/*").same_string ("image/*"))
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
parser : MIME_PARSE
|
||||
|
||||
end
|
||||
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-6-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-6-0 http://www.eiffel.com/developers/xml/configuration-1-6-0.xsd" name="test" uuid="7860561C-779A-4E45-A7B9-06A1E0E984E8">
|
||||
<target name="test">
|
||||
<root class="APPLICATION" feature="make"/>
|
||||
<file_rule>
|
||||
<exclude>/EIFGENs$</exclude>
|
||||
<exclude>/CVS$</exclude>
|
||||
<exclude>/.svn$</exclude>
|
||||
<exclude>/.git$</exclude>
|
||||
</file_rule>
|
||||
<option warning="true">
|
||||
<assertions precondition="true" postcondition="true" check="true" invariant="true" loop="true" supplier_precondition="true"/>
|
||||
</option>
|
||||
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
|
||||
<library name="http" location="..\..\http\http-safe.ecf" readonly="false"/>
|
||||
<library name="conneg" location="..\conneg-safe.ecf"/>
|
||||
<library name="testing" location="$ISE_LIBRARY\library\testing\testing-safe.ecf"/>
|
||||
<cluster name="test" location=".\" recursive="true"/>
|
||||
</target>
|
||||
</system>
|
||||
20
library/network/protocol/content_negotiation/test/test.ecf
Normal file
20
library/network/protocol/content_negotiation/test/test.ecf
Normal file
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-8-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-8-0 http://www.eiffel.com/developers/xml/configuration-1-8-0.xsd" name="test" uuid="7860561C-779A-4E45-A7B9-06A1E0E984E8">
|
||||
<target name="test">
|
||||
<root class="APPLICATION" feature="make"/>
|
||||
<file_rule>
|
||||
<exclude>/EIFGENs$</exclude>
|
||||
<exclude>/CVS$</exclude>
|
||||
<exclude>/.svn$</exclude>
|
||||
<exclude>/.git$</exclude>
|
||||
</file_rule>
|
||||
<option warning="true">
|
||||
<assertions precondition="true" postcondition="true" check="true" invariant="true" loop="true" supplier_precondition="true"/>
|
||||
</option>
|
||||
<library name="base" location="$ISE_LIBRARY\library\base\base.ecf"/>
|
||||
<library name="http" location="..\..\http\http.ecf" readonly="false"/>
|
||||
<library name="conneg" location="..\conneg.ecf"/>
|
||||
<library name="testing" location="$ISE_LIBRARY\library\testing\testing.ecf"/>
|
||||
<cluster name="test" location=".\" recursive="true"/>
|
||||
</target>
|
||||
</system>
|
||||
Reference in New Issue
Block a user