Updated Conneg library, added test cases
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
note
|
||||
description: "Summary description for {CHARACTER_ENCODING_VARIANT_RESULTS}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
CHARACTER_ENCODING_VARIANT_RESULTS
|
||||
feature
|
||||
character_type : detachable STRING
|
||||
set_character_type ( a_character_type: STRING)
|
||||
do
|
||||
character_type := a_character_type
|
||||
ensure
|
||||
set_character_type : a_character_type ~ character_type
|
||||
end
|
||||
|
||||
variant_header : detachable STRING
|
||||
set_variant_header
|
||||
do
|
||||
variant_header := "Accept-Charset"
|
||||
end
|
||||
|
||||
supported_variants : detachable LIST[STRING]
|
||||
set_supported_variants (a_supported : LIST[STRING])
|
||||
do
|
||||
supported_variants := a_supported
|
||||
ensure
|
||||
set_supported_variants : supported_variants = a_supported
|
||||
end
|
||||
|
||||
is_acceptable : BOOLEAN
|
||||
|
||||
set_acceptable ( acceptable : BOOLEAN)
|
||||
do
|
||||
is_acceptable := acceptable
|
||||
ensure
|
||||
is_acceptable = acceptable
|
||||
end
|
||||
|
||||
|
||||
note
|
||||
copyright: "2011-2011, Javier Velilla, Jocelyn Fiat and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
end
|
||||
44
library/protocol/CONNEG/src/compression_variant_results.e
Normal file
44
library/protocol/CONNEG/src/compression_variant_results.e
Normal file
@@ -0,0 +1,44 @@
|
||||
note
|
||||
description: "Summary description for {COMPRESSION_VARIANT_RESULTS}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
COMPRESSION_VARIANT_RESULTS
|
||||
|
||||
feature
|
||||
compression_type : detachable STRING
|
||||
set_compression_type ( a_compression_type: STRING)
|
||||
do
|
||||
compression_type := a_compression_type
|
||||
ensure
|
||||
set_compression_type : a_compression_type ~ compression_type
|
||||
end
|
||||
|
||||
variant_header : detachable STRING
|
||||
set_variant_header
|
||||
do
|
||||
variant_header := "Accept-Encoding"
|
||||
end
|
||||
|
||||
supported_variants : detachable LIST[STRING]
|
||||
set_supported_variants (a_supported : LIST[STRING])
|
||||
do
|
||||
supported_variants := a_supported
|
||||
ensure
|
||||
set_supported_variants : supported_variants = a_supported
|
||||
end
|
||||
|
||||
is_acceptable : BOOLEAN
|
||||
|
||||
set_acceptable ( acceptable : BOOLEAN)
|
||||
do
|
||||
is_acceptable := acceptable
|
||||
ensure
|
||||
is_acceptable = acceptable
|
||||
end
|
||||
note
|
||||
copyright: "2011-2011, Javier Velilla, Jocelyn Fiat and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
end
|
||||
@@ -109,29 +109,71 @@ feature -- Media Type Negotiation
|
||||
|
||||
feature -- Encoding Negotiation
|
||||
|
||||
charset_preference (server_charset_supported : LIST[STRING]; header: STRING) : STRING
|
||||
charset_preference (server_charset_supported : LIST[STRING]; header: STRING) : CHARACTER_ENCODING_VARIANT_RESULTS
|
||||
-- server_charset_supported represent a list of charset supported by the server.
|
||||
-- header represent the Accept-Charset header, ie, the client preferences.
|
||||
-- Return which Charset to use in a response, if the server support
|
||||
-- one Charset, or empty in other case.
|
||||
-- Reference: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.2
|
||||
local
|
||||
charset_match : STRING
|
||||
do
|
||||
Result := common.best_match (server_charset_supported, header)
|
||||
create Result
|
||||
if header.is_empty then
|
||||
-- the request has no Accept-Charset header, ie the header is empty, in this case use default charset encoding
|
||||
-- (UTF-8)
|
||||
Result.set_acceptable (TRUE)
|
||||
Result.set_character_type (charset_default)
|
||||
else
|
||||
-- select the best match, server support, client preferences
|
||||
charset_match := common.best_match (server_charset_supported, header)
|
||||
if charset_match.is_empty then
|
||||
-- The server does not support any of the compression types prefered by the client
|
||||
Result.set_acceptable (False)
|
||||
Result.set_supported_variants (server_charset_supported)
|
||||
else
|
||||
-- Set the best match
|
||||
Result.set_character_type(charset_match)
|
||||
Result.set_acceptable (True)
|
||||
Result.set_variant_header
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
feature -- Compression Negotiation
|
||||
|
||||
encoding_preference (server_encoding_supported : LIST[STRING]; header: STRING) : STRING
|
||||
encoding_preference (server_encoding_supported : LIST[STRING]; header: STRING) : COMPRESSION_VARIANT_RESULTS
|
||||
-- server_encoding_supported represent a list of encoding supported by the server.
|
||||
-- header represent the Accept-Encoding header, ie, the client preferences.
|
||||
-- Return which Encoding to use in a response, if the server support
|
||||
-- one Encoding, or empty in other case.
|
||||
-- Representation: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.3
|
||||
local
|
||||
compression_match : STRING
|
||||
do
|
||||
Result := common.best_match (server_encoding_supported, header)
|
||||
create Result
|
||||
if header.is_empty then
|
||||
-- the request has no Accept-Encoding header, ie the header is empty, in this case do not compress representations
|
||||
Result.set_acceptable (TRUE)
|
||||
Result.set_compression_type (encoding_default)
|
||||
else
|
||||
-- select the best match, server support, client preferences
|
||||
compression_match := common.best_match (server_encoding_supported, header)
|
||||
if compression_match.is_empty then
|
||||
-- The server does not support any of the compression types prefered by the client
|
||||
Result.set_acceptable (False)
|
||||
Result.set_supported_variants (server_encoding_supported)
|
||||
else
|
||||
-- Set the best match
|
||||
Result.set_compression_type(compression_match)
|
||||
Result.set_acceptable (True)
|
||||
Result.set_variant_header
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
feature -- Language Negotiation
|
||||
|
||||
language_preference (server_language_supported : LIST[STRING]; header: STRING) : LANGUAGE_VARIANT_RESULTS
|
||||
@@ -164,6 +206,8 @@ feature -- Language Negotiation
|
||||
end
|
||||
end
|
||||
|
||||
feature -- Apache Conneg Algorithm
|
||||
|
||||
note
|
||||
copyright: "2011-2011, Javier Velilla, Jocelyn Fiat and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
|
||||
Reference in New Issue
Block a user