Merge branch 'content_nego_review'

Conflicts:
	library/network/protocol/content_negotiation/src/conneg_server_side.e
	library/network/protocol/content_negotiation/src/parsers/common_accept_header_parser.e
	library/network/protocol/content_negotiation/test/conneg_server_side_test.e
This commit is contained in:
2013-10-18 21:30:10 +02:00
41 changed files with 1999 additions and 1758 deletions

View File

@@ -167,12 +167,12 @@ feature -- Content negotiation
res_attached: res /= Void
a_handler_attached: a_handler /= Void
local
l_conneg: CONNEG_SERVER_SIDE
l_conneg: SERVER_CONTENT_NEGOTIATION
h: HTTP_HEADER
l_media: MEDIA_TYPE_VARIANT_RESULTS
l_lang: LANGUAGE_VARIANT_RESULTS
l_charset: CHARACTER_ENCODING_VARIANT_RESULTS
l_encoding: COMPRESSION_VARIANT_RESULTS
l_media: like {SERVER_CONTENT_NEGOTIATION}.media_type_preference
l_lang: like {SERVER_CONTENT_NEGOTIATION}.language_preference
l_charset: like {SERVER_CONTENT_NEGOTIATION}.charset_preference
l_encoding: like {SERVER_CONTENT_NEGOTIATION}.encoding_preference
l_mime_types, l_langs, l_charsets, l_encodings: LIST [STRING]
l_vary_star: BOOLEAN
do
@@ -188,7 +188,7 @@ feature -- Content negotiation
l_conneg := a_handler.conneg (req)
l_mime_types := a_handler.mime_types_supported (req)
l_media := l_conneg.media_type_preference (l_mime_types, req.http_accept)
if not l_vary_star and l_mime_types.count > 1 and attached l_media.variant_header as l_media_variant then
if not l_vary_star and l_mime_types.count > 1 and attached l_media.media_type as l_media_variant then
h.add_header_key_value ({HTTP_HEADER_NAMES}.header_vary, l_media_variant)
end
if not l_media.is_acceptable then
@@ -196,26 +196,26 @@ feature -- Content negotiation
else
l_langs := a_handler.languages_supported (req)
l_lang := l_conneg.language_preference (l_langs, req.http_accept_language)
if not l_vary_star and l_langs.count > 1 and attached l_lang.variant_header as l_lang_variant then
if not l_vary_star and l_langs.count > 1 and attached l_lang.language as l_lang_variant then
h.add_header_key_value ({HTTP_HEADER_NAMES}.header_vary, l_lang_variant)
end
if not l_lang.is_acceptable then
handle_not_acceptable ("None of the requested languages were acceptable", l_langs, req, res)
else
if attached l_lang.type as l_language_type then
if attached l_lang.language as l_language_type then
h.put_content_language (l_language_type)
req.set_execution_variable (a_handler.Negotiated_language_execution_variable, l_language_type)
end
l_charsets := a_handler.charsets_supported (req)
l_charset := l_conneg.charset_preference (l_charsets, req.http_accept_charset)
if not l_vary_star and l_charsets.count > 1 and attached l_charset.variant_header as l_charset_variant then
if not l_vary_star and l_charsets.count > 1 and attached l_charset.charset as l_charset_variant then
h.add_header_key_value ({HTTP_HEADER_NAMES}.header_vary, l_charset_variant)
end
if not l_charset.is_acceptable then
handle_not_acceptable ("None of the requested character encodings were acceptable", l_charsets, req, res)
else
if attached l_media.type as l_media_type then
if attached l_charset.type as l_character_type then
if attached l_media.media_type as l_media_type then
if attached l_charset.charset as l_character_type then
h.put_content_type (l_media_type + "; charset=" + l_character_type)
req.set_execution_variable (a_handler.Negotiated_charset_execution_variable, l_charset)
else
@@ -225,13 +225,13 @@ feature -- Content negotiation
end
l_encodings := a_handler.encodings_supported (req)
l_encoding := l_conneg.encoding_preference (l_encodings, req.http_accept_encoding)
if not l_vary_star and l_encodings.count > 1 and attached l_encoding.variant_header as l_encoding_variant then
if not l_vary_star and l_encodings.count > 1 and attached l_encoding.encoding as l_encoding_variant then
h.add_header_key_value ({HTTP_HEADER_NAMES}.header_vary, l_encoding_variant)
end
if not l_encoding.is_acceptable then
handle_not_acceptable ("None of the requested transfer encodings were acceptable", l_encodings, req, res)
else
if attached l_encoding.type as l_compression_type then
if attached l_encoding.encoding as l_compression_type then
h.put_content_encoding (l_compression_type)
req.set_execution_variable (a_handler.Negotiated_encoding_execution_variable, l_compression_type)
end

View File

@@ -89,7 +89,7 @@ feature -- Access
deferred
end
conneg (req: WSF_REQUEST): CONNEG_SERVER_SIDE
conneg (req: WSF_REQUEST): SERVER_CONTENT_NEGOTIATION
-- Content negotiation for `req';
-- This would normally be a once object, ignoring `req'.
require
@@ -103,7 +103,7 @@ feature -- Access
req_attached: req /= Void
deferred
ensure
mime_types_supported_includes_default: Result.has (conneg (req).mime_default)
mime_types_supported_includes_default: Result.has (conneg (req).default_media_type)
end
languages_supported (req: WSF_REQUEST): LIST [STRING]
@@ -112,7 +112,7 @@ feature -- Access
req_attached: req /= Void
deferred
ensure
languages_supported_includes_default: Result.has (conneg (req).language_default)
languages_supported_includes_default: Result.has (conneg (req).default_language)
end
charsets_supported (req: WSF_REQUEST): LIST [STRING]
@@ -121,7 +121,7 @@ feature -- Access
req_attached: req /= Void
deferred
ensure
charsets_supported_includes_default: Result.has (conneg (req).charset_default)
charsets_supported_includes_default: Result.has (conneg (req).default_charset)
end
encodings_supported (req: WSF_REQUEST): LIST [STRING]
@@ -130,7 +130,7 @@ feature -- Access
req_attached: req /= Void
deferred
ensure
encodings_supported_includes_default: Result.has (conneg (req).encoding_default)
encodings_supported_includes_default: Result.has (conneg (req).default_encoding)
end
additional_variant_headers (req: WSF_REQUEST): detachable LIST [STRING]

View File

@@ -351,31 +351,9 @@ feature -- Helper
-- Does client accepts content_type for the response?
--| Based on header "Accept:" that can be for instance
--| text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
local
i, j: INTEGER
do
if attached http_accept as l_accept then
i := l_accept.substring_index (a_content_type, 1)
if i > 0 then
-- contains the text, now check if this is the exact text
if
i = 1 -- At the beginning of text
or else l_accept[i-1].is_space -- preceded by space
or else l_accept[i-1] = ',' -- preceded by other mime type
then
j := i + a_content_type.count
if l_accept.valid_index (j) then
Result := l_accept[j] = ',' -- followed by other mime type
or else l_accept[j] = ';' -- followed by quality ;q=...
or else l_accept[j].is_space -- followed by space
else -- end of text
Result := True
end
end
end
Result := l_accept.has_substring (a_content_type)
else
Result := True
if attached (create {SERVER_MEDIA_TYPE_NEGOTIATION}.make (a_content_type.as_string_8)).preference (<<a_content_type.as_string_8>>, http_accept) as l_variants then
Result := l_variants.is_acceptable
end
end

View File

@@ -15,6 +15,7 @@
<library name="error" location="..\..\utility\general\error\error-safe.ecf"/>
<library name="ewsgi" location="..\ewsgi\ewsgi-safe.ecf"/>
<library name="http" location="..\..\network\protocol\http\http-safe.ecf"/>
<library name="conneg" location="..\..\network\protocol\content_negotiation\conneg-safe.ecf"/>
<library name="time" location="$ISE_LIBRARY\library\time\time-safe.ecf"/>
<library name="uri" location="$ISE_LIBRARY\library\text\uri\uri-safe.ecf"/>
<library name="uri_template" location="..\..\text\parser\uri_template\uri_template-safe.ecf"/>

View File

@@ -15,6 +15,7 @@
<library name="time" location="$ISE_LIBRARY\library\time\time.ecf"/>
<library name="error" location="../../utility/general/error/error.ecf"/>
<library name="http" location="../../network/protocol/http/http.ecf"/>
<library name="conneg" location="..\..\network\protocol\content_negotiation\conneg.ecf"/>
<library name="uri_template"
location="../../text/parser/uri_template/uri_template.ecf"/>
<library name="encoder"