Class renaming for content_negotiation

Splitted SERVER_CONTENT_NEGOTIATION in 4 differents classes for each kind of negotiation
Changed to use ITERABLE over LIST for supported variants arguments
Factorized some code for http parameter parsing such as q=1.0;note="blabla"  and so on
Integrated within EWF
This commit is contained in:
2013-10-18 16:18:22 +02:00
parent d376f99832
commit 88e6837222
25 changed files with 938 additions and 716 deletions

View File

@@ -16,10 +16,10 @@ feature {NONE} -- Initialization
make
local
mime_parse : HTTP_ACCEPT_MEDIA_TYPE_PARSER
mime_parse : HTTP_ACCEPT_MEDIA_TYPE_UTILITIES
accept : STRING
charset_parse : HTTP_ANY_ACCEPT_HEADER_PARSER
language : HTTP_ACCEPT_LANGUAGE_PARSER
charset_parse : HTTP_ANY_ACCEPT_HEADER_UTILITIES
language : HTTP_ACCEPT_LANGUAGE_UTILITIES
do
create mime_parse
-- parse_result := mime_parse.parse_mime_type ("application/xhtml;q=0.5")

View File

@@ -23,26 +23,24 @@ feature {NONE} -- Events
feature -- Helpers
format (a_common: HTTP_ANY_ACCEPT_HEADER): STRING
format (a_common: HTTP_ANY_ACCEPT): STRING
-- Representation of the current object
do
create Result.make_from_string ("(")
if attached a_common.field as t then
if attached a_common.value as t then
Result.append_string ("'" + t + "',")
end
Result.append_string (" {")
from
a_common.params.start
until
a_common.params.after
loop
Result.append ("'" + a_common.params.key_for_iteration + "':'" + a_common.params.item_for_iteration + "',");
a_common.params.forth
if attached a_common.parameters as l_parameters then
across
l_parameters as ic
loop
Result.append ("'" + ic.key + "':'" + ic.item + "',");
end
end
Result.append ("})")
end
feature -- Test routines
test_parse_charsets
@@ -74,6 +72,6 @@ feature -- Test routines
assert ("Expected unicode-1-1", parser.best_match (charset_supported, "unicode-1-1;q=1").same_string ("unicode-1-1"))
end
parser : HTTP_ANY_ACCEPT_HEADER_PARSER
parser : HTTP_ANY_ACCEPT_HEADER_UTILITIES
end

View File

@@ -34,8 +34,8 @@ feature -- Test routines
media_variants := conneg.media_type_preference (mime_types_supported, "text/html")
assert ("Expected Not Acceptable", not media_variants.is_acceptable)
if attached media_variants.supported_variants as l_supported_variants then
assert ("Same Value at 1",mime_types_supported.first.same_string (l_supported_variants.first))
assert ("Same count",mime_types_supported.count = l_supported_variants.count)
assert ("Same Value at 1", same_text (first_of (mime_types_supported), first_of (l_supported_variants)))
assert ("Same count", count_of (mime_types_supported) = count_of (l_supported_variants))
else
assert ("Has supported_variants results", False)
end
@@ -72,8 +72,8 @@ feature -- Test routines
charset_variants := conneg.charset_preference (charset_supported, "unicode-1-1")
assert ("Expected Not Acceptable", not charset_variants.is_acceptable)
if attached charset_variants.supported_variants as l_supported_variants then
assert ("Same Value at 1",charset_supported.first.same_string (l_supported_variants.first))
assert ("Same count",charset_supported.count = l_supported_variants.count)
assert ("Same Value at 1", same_text (first_of (charset_supported), first_of (l_supported_variants)))
assert ("Same count",charset_supported.count = count_of (l_supported_variants))
else
assert("Has supported_variants results", False)
end
@@ -109,8 +109,8 @@ feature -- Test routines
compression_variants := conneg.encoding_preference (compression_supported, "gzip")
assert ("Expected Not Acceptable", not compression_variants.is_acceptable)
if attached compression_variants.supported_variants as l_supported_variants then
assert ("Same Value at 1",compression_supported.first.same_string (l_supported_variants.first))
assert ("Same count",compression_supported.count = l_supported_variants.count)
assert ("Same Value at 1", same_text (first_of (compression_supported), first_of (l_supported_variants)))
assert ("Same count",compression_supported.count = count_of (l_supported_variants))
else
assert ("Has supported_variants results", False)
end
@@ -153,8 +153,8 @@ feature -- Test routines
assert ("Variant Header", attached language_variants.vary_header_value as l_variant_header and then l_variant_header.same_string ("Accept-Language"))
assert ("Language type is Void",language_variants.language = Void)
if attached language_variants.supported_variants as l_supported_variants then
assert ("Same Value at 1", languages_supported.first.same_string (l_supported_variants.first))
assert ("Same count",languages_supported.count = l_supported_variants.count)
assert ("Same Value at 1", same_text (first_of (languages_supported), first_of (l_supported_variants)))
assert ("Same count",languages_supported.count = count_of (l_supported_variants))
else
assert ("Has supported variants results", False)
end
@@ -175,5 +175,36 @@ feature -- Test routines
end
feature -- Implementation
conneg : CONNEG_SERVER_SIDE
conneg : SERVER_CONTENT_NEGOTIATION
same_text (s1,s2: detachable READABLE_STRING_8): BOOLEAN
do
if s1 = Void then
Result := s2 = Void
elseif s2 = Void then
Result := False
else
Result := s1.same_string (s2)
end
end
count_of (i: ITERABLE [READABLE_STRING_8]): INTEGER
do
across
i as ic
loop
Result := Result + 1
end
end
first_of (i: ITERABLE [READABLE_STRING_8]): detachable READABLE_STRING_8
do
across
i as ic
until
ic.item /= Void
loop
end
end
end

View File

@@ -3,3 +3,16 @@ Catcall detected in {READABLE_STRING_8}.make_from_string for arg#1: expected REA
Catcall detected in {READABLE_STRING_8}.make_from_string for arg#1: expected READABLE_STRING_8 but got Void
Catcall detected in {READABLE_STRING_8}.make_from_string for arg#1: expected READABLE_STRING_8 but got Void
Catcall detected in {READABLE_STRING_8}.make_from_string for arg#1: expected READABLE_STRING_8 but got Void
Catcall detected in {READABLE_STRING_8}.make_from_string for arg#1: expected READABLE_STRING_8 but got Void
Catcall detected in {READABLE_STRING_8}.make_from_string for arg#1: expected READABLE_STRING_8 but got Void
Catcall detected in {READABLE_STRING_8}.make_from_string for arg#1: expected READABLE_STRING_8 but got Void
Catcall detected in {READABLE_STRING_8}.make_from_string for arg#1: expected READABLE_STRING_8 but got Void
Catcall detected in {READABLE_STRING_8}.make_from_string for arg#1: expected READABLE_STRING_8 but got Void
Catcall detected in {READABLE_STRING_8}.make_from_string for arg#1: expected READABLE_STRING_8 but got Void
Catcall detected in {READABLE_STRING_8}.make_from_string for arg#1: expected READABLE_STRING_8 but got Void
Catcall detected in {READABLE_STRING_8}.make_from_string for arg#1: expected READABLE_STRING_8 but got Void
Catcall detected in {READABLE_STRING_8}.make_from_string for arg#1: expected READABLE_STRING_8 but got Void
Catcall detected in {READABLE_STRING_8}.make_from_string for arg#1: expected READABLE_STRING_8 but got Void
Catcall detected in {READABLE_STRING_8}.make_from_string for arg#1: expected READABLE_STRING_8 but got Void
Catcall detected in {READABLE_STRING_8}.make_from_string for arg#1: expected READABLE_STRING_8 but got Void
Catcall detected in {READABLE_STRING_8}.make_from_string for arg#1: expected READABLE_STRING_8 but got Void

View File

@@ -34,14 +34,11 @@ feature -- Helpers
Result.append_string (" '" + st + "',")
end
Result.append_string (" {")
if attached a_language.params as l_params then
from
l_params.start
until
l_params.after
if attached a_language.parameters as l_params then
across
l_params as ic
loop
Result.append ("'" + l_params.key_for_iteration + "':'"+ l_params.item_for_iteration + "',");
l_params.forth
Result.append ("'" + ic.key + "':'"+ ic.item + "',");
end
end
Result.append ("})")
@@ -137,7 +134,7 @@ feature -- Test routines
parser : HTTP_ACCEPT_LANGUAGE_PARSER
parser : HTTP_ACCEPT_LANGUAGE_UTILITIES
end

View File

@@ -38,13 +38,10 @@ feature -- Helper
end
Result.append_string (" {")
if attached a_mediatype.parameters as l_params then
from
l_params.start
until
l_params.after
across
l_params as ic
loop
Result.append ("'" + l_params.key_for_iteration + "':'" + l_params.item_for_iteration + "',");
l_params.forth
Result.append ("'" + ic.key + "':'" + ic.item + "',");
end
end
Result.append ("})")
@@ -148,7 +145,7 @@ feature -- Test routines
parser : HTTP_ACCEPT_MEDIA_TYPE_PARSER
parser : HTTP_ACCEPT_MEDIA_TYPE_UTILITIES
end