Updated content_negotiation with better class names and feature names.

Minor semantic changes in VARIANTS classes
Factorized some code in HTTP_ACCEPT_LANGUAGE
This commit is contained in:
2013-10-15 23:19:12 +02:00
parent 3072ce7dec
commit d376f99832
26 changed files with 1185 additions and 1052 deletions

View File

@@ -1,6 +1,6 @@
note
description: "[
{CHARACTER_ENCODING_VARIANT_RESULTS}
{HTTP_ACCEPT_CHARSET_VARIANTS}
Represent the character sets results between client preferences and character sets variants supported by the server.
If the server is unable to supports the requested Accept-Charset values, the server can build
a response with the list of supported character sets.
@@ -10,20 +10,22 @@ note
revision: "$Revision$"
class
CHARACTER_ENCODING_VARIANT_RESULTS
HTTP_ACCEPT_CHARSET_VARIANTS
inherit
HTTP_ACCEPT_VARIANTS
rename
variant_value as charset
end
VARIANT_RESULTS
create
make
feature -- Change
feature -- Change Element
set_variant_header
-- Set variant header as `Accept-Charset'
set_vary_header_value
do
variant_header := {HTTP_HEADER_NAMES}.header_accept_charset -- "Accept-Charset"
vary_header_value := {HTTP_HEADER_NAMES}.header_accept_charset -- "Accept-Charset"
end
note

View File

@@ -1,28 +1,31 @@
note
description: "[
{COMPRESSION_VARIANT_RESULTS}
Represent the compression results between client preferences and ccompression variants supported by the server.
{HTTP_ACCEPT_ENCODING_VARIANTS}
Represent the encoding results between client preferences and encoding variants supported by the server.
If the server is unable to supports the requested Accept-Encoding values, the server can build
a response with the list of supported encodings/compressions
a response with the list of supported encodings
]"
date: "$Date$"
revision: "$Revision$"
EIS: "name= Compression", "src=http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.3", "protocol=uri"
class
COMPRESSION_VARIANT_RESULTS
HTTP_ACCEPT_ENCODING_VARIANTS
inherit
HTTP_ACCEPT_VARIANTS
rename
variant_value as encoding
end
VARIANT_RESULTS
create
make
feature -- Change
feature -- Change Element
set_variant_header
-- Set variant_header as `Accept-Encoding'
set_vary_header_value
do
variant_header := {HTTP_HEADER_NAMES}.header_accept_encoding -- "Accept-Encoding"
vary_header_value := {HTTP_HEADER_NAMES}.header_accept_encoding -- "Accept-Encoding"
end
note

View File

@@ -1,6 +1,6 @@
note
description: "[
{LANGUAGE_VARIANT_RESULTS}.
{HTTP_ACCEPT_LANGUAGE_VARIANTS}.
Represent the language results between client preferences and language variants supported by the server.
If the server is unable to supports the requested Accept-Language values, the server can build
a response with the list of supported languages
@@ -9,18 +9,22 @@ note
revision: "$Revision$"
class
LANGUAGE_VARIANT_RESULTS
HTTP_ACCEPT_LANGUAGE_VARIANTS
inherit
HTTP_ACCEPT_VARIANTS
rename
variant_value as language
end
VARIANT_RESULTS
create
make
feature -- Change Element
feature -- Change
set_variant_header
-- Set variant header as 'Accept-Language'
set_vary_header_value
do
variant_header := {HTTP_HEADER_NAMES}.header_accept_language -- "Accept-Language"
vary_header_value := {HTTP_HEADER_NAMES}.header_accept_language -- "Accept-Language"
end
note

View File

@@ -1,7 +1,7 @@
note
description: "[
{MEDIA_TYPE_VARIANT_RESULTS}.
Represent the media type results between client preferences and media type variants supported by the server..
{HTTP_ACCEPT_MEDIA_TYPE_VARIANTS}.
Represents the media type results between client preferences and media type variants supported by the server..
If the server is unable to supports the requested Accept values, the server can build
a response with the list of supported representations
]"
@@ -9,18 +9,22 @@ note
revision: "$Revision$"
class
MEDIA_TYPE_VARIANT_RESULTS
HTTP_ACCEPT_MEDIA_TYPE_VARIANTS
inherit
HTTP_ACCEPT_VARIANTS
rename
variant_value as media_type
end
VARIANT_RESULTS
create
make
feature -- Change Element
feature -- Change
set_variant_header
-- Set variant header as `Accept'
set_vary_header_value
do
variant_header := {HTTP_HEADER_NAMES}.header_accept -- "Accept"
vary_header_value := {HTTP_HEADER_NAMES}.header_accept -- "Accept"
end
note

View File

@@ -0,0 +1,92 @@
note
description: "Generic {HTTP_ACCEPT_VARIANTS}.with common functionality to most header variants.."
date: "$Date$"
revision: "$Revision$"
deferred class
HTTP_ACCEPT_VARIANTS
feature {NONE} -- Initialization
make
do
end
feature -- Change
set_vary_header_value
-- Set the `vary_header_value'
deferred
ensure
is_valid_header_set : is_valid_header_name (vary_header_value)
end
feature -- Access
vary_header_value: detachable READABLE_STRING_8
-- Name of header to be added to the Vary header of the response
-- this indicates the Accept-* header source of the matched `variant_value' if any,
-- if this is using the default, the `vary_header_value' is Void.
supported_variants: detachable LIST [READABLE_STRING_8]
-- Set of supported variants for the response
variant_value: detachable READABLE_STRING_8
-- Associated value, it could be value of:
-- content type
-- language
-- character set
-- encoding.
feature -- Status_Report
is_acceptable: BOOLEAN
-- is the current variant accepted?
is_valid_header_name (a_header_name: detachable READABLE_STRING_8): BOOLEAN
-- is `a_header_name' a valid accept header name?
note
EIS:"name=Accept", "src=http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1", "protocol=uri"
EIS:"name=Accept-Charset", "src=http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.2", "protocol=uri"
EIS:"name=Accept-Encoding", "src=http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.3", "protocol=uri"
EIS:"name=Accept-Language", "src=http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.4", "protocol=uri"
do
if a_header_name /= Void then
Result := a_header_name.same_string ({HTTP_HEADER_NAMES}.header_accept) -- "Accept",
or else a_header_name.same_string ({HTTP_HEADER_NAMES}.header_accept_language) -- "Accept-Language",
or else a_header_name.same_string ({HTTP_HEADER_NAMES}.header_accept_encoding) -- "Accept-Encoding",
or else a_header_name.same_string ({HTTP_HEADER_NAMES}.header_accept_charset) -- "Accept-Charset"
end
end
feature -- Change Element
set_variant_value (v: READABLE_STRING_8)
-- Set `variant_value' as `v'
do
variant_value := v
ensure
type_set: attached variant_value as l_variant implies l_variant = v
end
set_acceptable (b: BOOLEAN)
-- Set `is_acceptable' with `b'
do
is_acceptable := b
ensure
is_acceptable_set: is_acceptable = b
end
set_supported_variants (a_supported: LIST [READABLE_STRING_8])
-- Set `supported variants' with `a_supported'
do
supported_variants := a_supported
ensure
set_supported_variants: attached supported_variants as l_supported_variants implies l_supported_variants = a_supported
end
note
copyright: "2011-2013, Javier Velilla, Jocelyn Fiat, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
end

View File

@@ -1,91 +0,0 @@
note
description: "Generic {VARIANT_RESULTS}.with common functionality to most header variants.."
date: "$Date$"
revision: "$Revision$"
deferred class
VARIANT_RESULTS
feature -- Access
variant_header: detachable READABLE_STRING_8
-- Name of variant header to be added to the Vary header of the response
supported_variants: detachable LIST [READABLE_STRING_8]
-- Set of supported variants for the response
is_acceptable: BOOLEAN
-- is the current variant accepted?
type: detachable READABLE_STRING_8
-- Associated type, it could be:
-- media type
-- language
-- character_sets
-- encoding.
feature {NONE} -- Implementation
accept_headers_set: ARRAY [READABLE_STRING_8]
-- Set of valid accept headers headers
note
EIS:"name=Accept", "src=http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1", "protocol=uri"
EIS:"name=Accept-Charset", "src=http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.2", "protocol=uri"
EIS:"name=Accept-Encoding", "src=http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.3", "protocol=uri"
EIS:"name=Accept-Language", "src=http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.4", "protocol=uri"
once
Result:= <<
{HTTP_HEADER_NAMES}.header_accept, -- "Accept",
{HTTP_HEADER_NAMES}.header_accept_language, -- "Accept-Language",
{HTTP_HEADER_NAMES}.header_accept_encoding, -- "Accept-Encoding",
{HTTP_HEADER_NAMES}.header_accept_charset --"Accept-Charset"
>>
Result.compare_objects
end
feature -- Status_Report
is_valid_header (a_header: READABLE_STRING_8): BOOLEAN
-- is `a_header' a valid accept header?
do
Result := accept_headers_set.has (a_header)
end
feature -- Change Element
set_type (a_type: READABLE_STRING_8)
-- Set `type' as `a_type'
do
type := a_type
ensure
type_set: attached type as l_type implies l_type = a_type
end
set_acceptable (acceptable: BOOLEAN)
-- Set `is_acceptable' with `acceptable'
do
is_acceptable := acceptable
ensure
is_acceptable_set: is_acceptable = acceptable
end
set_variant_header
-- Set variant header
deferred
ensure
is_valid_header_set : attached variant_header as l_header implies is_valid_header (l_header)
end
set_supported_variants (a_supported: LIST [READABLE_STRING_8])
-- Set `supported variants' with `a_supported'
do
supported_variants := a_supported
ensure
set_supported_variants: attached supported_variants as l_supported_variants implies l_supported_variants = a_supported
end
note
copyright: "2011-2013, Javier Velilla, Jocelyn Fiat, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
end