Removed http classes related to http expectations.
Updated code based on the code review. Still work in progress
This commit is contained in:
@@ -1,51 +0,0 @@
|
||||
note
|
||||
description: "Summary description for {HTTP_CLIENT_HEADER_EXPECTATION}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
HTTP_CLIENT_HEADER_EXPECTATION
|
||||
inherit
|
||||
HTTP_CLIENT_RESPONSE_EXPECTATION
|
||||
create
|
||||
make
|
||||
|
||||
feature {NONE} -- Initializtion
|
||||
make (a_header: STRING_32; a_value : STRING)
|
||||
-- Create and Initialize a header expectation
|
||||
do
|
||||
header := a_header
|
||||
value := a_value
|
||||
ensure
|
||||
header_set : header ~ a_header
|
||||
value_set : value ~ a_value
|
||||
end
|
||||
|
||||
feature -- Result expected
|
||||
expected (resp: HTTP_CLIENT_RESPONSE): BOOLEAN
|
||||
-- is `header name and value expected' equals to resp.header(name)?
|
||||
do
|
||||
if attached {READABLE_STRING_8} resp.header (header) as l_value then
|
||||
if l_value.same_string (l_value) then
|
||||
Result := true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
header : STRING
|
||||
-- header name
|
||||
value : STRING
|
||||
-- header value
|
||||
;note
|
||||
copyright: "2011-2013, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
source: "[
|
||||
Eiffel Software
|
||||
5949 Hollister Ave., Goleta, CA 93117 USA
|
||||
Telephone 805-685-1006, Fax 805-685-6869
|
||||
Website http://www.eiffel.com
|
||||
Customer support http://support.eiffel.com
|
||||
]"
|
||||
end
|
||||
@@ -1,48 +0,0 @@
|
||||
note
|
||||
description: "Summary description for {HTTP_CLIENT_RESPONSE_BODY_EXPECTATION}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
HTTP_CLIENT_RESPONSE_BODY_EXPECTATION
|
||||
inherit
|
||||
HTTP_CLIENT_RESPONSE_EXPECTATION
|
||||
create
|
||||
make
|
||||
|
||||
feature {NONE} -- Initializtion
|
||||
make (a_body : detachable STRING_32)
|
||||
-- Create and Initialize a body expectation
|
||||
do
|
||||
body := a_body
|
||||
ensure
|
||||
body_set : body ~ a_body
|
||||
end
|
||||
|
||||
feature -- Result expected
|
||||
expected (resp: HTTP_CLIENT_RESPONSE): BOOLEAN
|
||||
-- is `body expected' equals to resp.body?
|
||||
do
|
||||
if body = Void and then resp.body = Void then
|
||||
Result := True
|
||||
elseif attached resp.body as l_body and then attached body as c_body then
|
||||
Result := l_body.is_case_insensitive_equal (c_body)
|
||||
end
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
body : detachable STRING_32
|
||||
-- expected body
|
||||
|
||||
;note
|
||||
copyright: "2011-2013, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
source: "[
|
||||
Eiffel Software
|
||||
5949 Hollister Ave., Goleta, CA 93117 USA
|
||||
Telephone 805-685-1006, Fax 805-685-6869
|
||||
Website http://www.eiffel.com
|
||||
Customer support http://support.eiffel.com
|
||||
]"
|
||||
end
|
||||
@@ -1,27 +0,0 @@
|
||||
note
|
||||
description: "Summary description for {HTTP_CLIENT_RESPONSE_EXPECTATION}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
deferred class
|
||||
HTTP_CLIENT_RESPONSE_EXPECTATION
|
||||
|
||||
feature
|
||||
|
||||
expected (resp: HTTP_CLIENT_RESPONSE): BOOLEAN
|
||||
deferred
|
||||
end
|
||||
|
||||
note
|
||||
copyright: "2011-2013, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
source: "[
|
||||
Eiffel Software
|
||||
5949 Hollister Ave., Goleta, CA 93117 USA
|
||||
Telephone 805-685-1006, Fax 805-685-6869
|
||||
Website http://www.eiffel.com
|
||||
Customer support http://support.eiffel.com
|
||||
]"
|
||||
|
||||
end
|
||||
@@ -1,42 +0,0 @@
|
||||
note
|
||||
description: "Summary description for {HTTP_CLIENT_RESPONSE_STATUS_CODE_EXPECTATION}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
HTTP_CLIENT_RESPONSE_STATUS_CODE_EXPECTATION
|
||||
inherit
|
||||
HTTP_CLIENT_RESPONSE_EXPECTATION
|
||||
|
||||
create make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
make (a_status : INTEGER_32)
|
||||
do
|
||||
status := a_status
|
||||
ensure
|
||||
status_set : status = a_status
|
||||
end
|
||||
|
||||
feature -- Result Expected
|
||||
expected (resp: HTTP_CLIENT_RESPONSE): BOOLEAN
|
||||
-- is `status' expected equals to resp.status?
|
||||
do
|
||||
Result := status = resp.status
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
status : INTEGER_32
|
||||
-- status expected
|
||||
;note
|
||||
copyright: "2011-2013, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
source: "[
|
||||
Eiffel Software
|
||||
5949 Hollister Ave., Goleta, CA 93117 USA
|
||||
Telephone 805-685-1006, Fax 805-685-6869
|
||||
Website http://www.eiffel.com
|
||||
Customer support http://support.eiffel.com
|
||||
]"
|
||||
end
|
||||
@@ -1,121 +0,0 @@
|
||||
note
|
||||
description: "Summary description for {TEST_HTTP_CLIENT_WITH_HTTPBIN}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
EIS: "name=HTTP TESTING", "protocol=uri", "src=http://httpbin.org/"
|
||||
|
||||
class
|
||||
TEST_HTTP_CLIENT_WITH_HTTPBIN
|
||||
|
||||
inherit
|
||||
EQA_TEST_SET
|
||||
|
||||
feature
|
||||
test_origin_ip
|
||||
local
|
||||
h: LIBCURL_HTTP_CLIENT
|
||||
sess: HTTP_CLIENT_SESSION
|
||||
resp : detachable HTTP_CLIENT_RESPONSE
|
||||
l_location : detachable READABLE_STRING_8
|
||||
body : STRING
|
||||
context : HTTP_CLIENT_REQUEST_CONTEXT
|
||||
s: READABLE_STRING_8
|
||||
do
|
||||
create h.make
|
||||
sess := h.new_session ("http://httpbin.org/")
|
||||
resp := sess.get ("",void)
|
||||
assert ("Expected Status 200 ok", resp.status = 200)
|
||||
end
|
||||
|
||||
test_status_code
|
||||
local
|
||||
h: LIBCURL_HTTP_CLIENT
|
||||
sess: HTTP_CLIENT_SESSION
|
||||
resp : detachable HTTP_CLIENT_RESPONSE
|
||||
l_location : detachable READABLE_STRING_8
|
||||
body : STRING
|
||||
context : HTTP_CLIENT_REQUEST_CONTEXT
|
||||
s: READABLE_STRING_8
|
||||
do
|
||||
create h.make
|
||||
sess := h.new_session ("http://httpbin.org/")
|
||||
assert ("Expected Status 200 ok", (create {HTTP_CLIENT_RESPONSE_STATUS_CODE_EXPECTATION}.make(200)).expected(sess.get ("",void)) )
|
||||
end
|
||||
|
||||
test_body
|
||||
local
|
||||
h: LIBCURL_HTTP_CLIENT
|
||||
sess: HTTP_CLIENT_SESSION
|
||||
resp : detachable HTTP_CLIENT_RESPONSE
|
||||
l_location : detachable READABLE_STRING_8
|
||||
body : STRING
|
||||
context : HTTP_CLIENT_REQUEST_CONTEXT
|
||||
s: READABLE_STRING_8
|
||||
do
|
||||
create h.make
|
||||
sess := h.new_session ("http://httpbin.org/")
|
||||
assert ("Expected no body", (create {HTTP_CLIENT_RESPONSE_BODY_EXPECTATION}.make(expected_body_get)).expected(sess.get ("get",void)) )
|
||||
end
|
||||
|
||||
test_body_status
|
||||
local
|
||||
h: LIBCURL_HTTP_CLIENT
|
||||
sess: HTTP_CLIENT_SESSION
|
||||
resp : detachable HTTP_CLIENT_RESPONSE
|
||||
l_location : detachable READABLE_STRING_8
|
||||
body : STRING
|
||||
context : HTTP_CLIENT_REQUEST_CONTEXT
|
||||
s: READABLE_STRING_8
|
||||
do
|
||||
create h.make
|
||||
sess := h.new_session ("http://httpbin.org/")
|
||||
--assert ("Expected no body", (create {HTTP_CLIENT_RESPONSE_STATUS_CODE_EXPECTATION}.make(200) + create {HTTP_CLIENT_RESPONSE_BODY_EXPECTATION}.make(expected_body_get)).expected(sess.get ("get",void)) )
|
||||
end
|
||||
|
||||
|
||||
test_after_post_should_continue_working
|
||||
local
|
||||
h: LIBCURL_HTTP_CLIENT
|
||||
sess: HTTP_CLIENT_SESSION
|
||||
resp : detachable HTTP_CLIENT_RESPONSE
|
||||
l_location : detachable READABLE_STRING_8
|
||||
body : STRING
|
||||
context : HTTP_CLIENT_REQUEST_CONTEXT
|
||||
s: READABLE_STRING_8
|
||||
do
|
||||
create h.make
|
||||
sess := h.new_session ("http://httpbin.org/")
|
||||
resp := sess.get ("",void)
|
||||
assert ("Expected Status 200 ok", resp.status = 200)
|
||||
|
||||
create context.make
|
||||
context.headers.put ("text/plain;charset=UTF-8", "Content-Type")
|
||||
resp := sess.post ("post", context, "testing post")
|
||||
assert ("Expected Status 200 ok", resp.status = 200)
|
||||
|
||||
sess := h.new_session ("http://httpbin.org/")
|
||||
resp := sess.get ("",void)
|
||||
assert ("Expected Status 200 ok", resp.status = 200)
|
||||
|
||||
sess := h.new_session ("http://httpbin.org/")
|
||||
resp := sess.get ("redirect/1",void)
|
||||
assert ("Expected Status 200 ok", resp.status = 200)
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
expected_body_get : STRING_32 = "[
|
||||
{
|
||||
"url": "http://httpbin.org/get",
|
||||
"args": {},
|
||||
"headers": {
|
||||
"Host": "httpbin.org",
|
||||
"Connection": "close",
|
||||
"Accept": "*/*"
|
||||
},
|
||||
"origin": "190.177.106.187"
|
||||
}
|
||||
]"
|
||||
end
|
||||
@@ -1,6 +1,5 @@
|
||||
note
|
||||
description: "Summary description for {CONNEG_SERVER_SIDE}. Utility class to support Server Side Content Negotiation "
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
description: "[
|
||||
@@ -44,48 +43,48 @@ feature -- Initialization
|
||||
feature -- AccessServer Side Defaults Formats
|
||||
|
||||
mime_default: READABLE_STRING_8
|
||||
-- Media types which are acceptable for the response
|
||||
-- Media type which is acceptable for the response.
|
||||
|
||||
language_default: READABLE_STRING_8
|
||||
-- Set of natural languages that are preferred as a response to the request
|
||||
-- Natural language that is preferred as a response to the request.
|
||||
|
||||
charset_default: READABLE_STRING_8
|
||||
-- Character sets are acceptable for the response.
|
||||
-- Character set that is acceptable for the response.
|
||||
|
||||
encoding_default: READABLE_STRING_8
|
||||
-- Content-codings that are acceptable in the response.
|
||||
-- Content-coding that is acceptable in the response.
|
||||
|
||||
feature -- Change Element
|
||||
|
||||
set_mime_default (a_mime: READABLE_STRING_8)
|
||||
-- set the mime_default with `a_mime'
|
||||
-- Set the mime_default with `a_mime'
|
||||
do
|
||||
mime_default := a_mime
|
||||
ensure
|
||||
set_mime_default: a_mime = mime_default
|
||||
mime_default_set: a_mime = mime_default
|
||||
end
|
||||
|
||||
set_language_default (a_language: READABLE_STRING_8)
|
||||
-- set the language_default with `a_language'
|
||||
-- Set the language_default with `a_language'
|
||||
do
|
||||
language_default := a_language
|
||||
ensure
|
||||
set_language: a_language = language_default
|
||||
language_default_set: a_language = language_default
|
||||
end
|
||||
|
||||
set_charset_default (a_charset: READABLE_STRING_8)
|
||||
-- set the charset_default with `a_charset'
|
||||
-- Set the charset_default with `a_charset'
|
||||
do
|
||||
charset_default := a_charset
|
||||
ensure
|
||||
set_charset: a_charset = charset_default
|
||||
charset_default_set: a_charset = charset_default
|
||||
end
|
||||
|
||||
set_encoding_default (a_encoding: READABLE_STRING_8)
|
||||
do
|
||||
encoding_default := a_encoding
|
||||
ensure
|
||||
set_encoding: a_encoding = encoding_default
|
||||
encoding_default_set: a_encoding = encoding_default
|
||||
end
|
||||
|
||||
|
||||
@@ -95,8 +94,8 @@ feature -- Media Type Negotiation
|
||||
media_type_preference (a_mime_types_supported: LIST [READABLE_STRING_8]; a_header: detachable READABLE_STRING_8): MEDIA_TYPE_VARIANT_RESULTS
|
||||
-- `a_mime_types_supported' represent media types supported by the server.
|
||||
-- `a_header represent' the Accept header, ie, the client preferences.
|
||||
-- Return which media type to use for representaion in a response, if the server support
|
||||
-- one media type, or empty in other case.
|
||||
-- Return which media type to use for representation in a response, if the server supports
|
||||
-- the requested media type, or empty in other case.
|
||||
note
|
||||
EIS: "name=media type", "src=http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1", "protocol=uri"
|
||||
local
|
||||
@@ -106,17 +105,17 @@ feature -- Media Type Negotiation
|
||||
if a_header = Void or else a_header.is_empty then
|
||||
-- the request has no Accept header, ie the header is empty, in this case we use the default format
|
||||
Result.set_acceptable (TRUE)
|
||||
Result.set_media_type (mime_default)
|
||||
Result.set_type (mime_default)
|
||||
else
|
||||
-- select the best match, server support, client preferences
|
||||
l_mime_match := mime.best_match (a_mime_types_supported, a_header)
|
||||
if l_mime_match.is_empty then
|
||||
-- The server does not support any of the media types prefered by the client
|
||||
-- The server does not support any of the media types preferred by the client
|
||||
Result.set_acceptable (False)
|
||||
Result.set_supported_variants (a_mime_types_supported)
|
||||
else
|
||||
-- Set the best match
|
||||
Result.set_media_type (l_mime_match)
|
||||
Result.set_type (l_mime_match)
|
||||
Result.set_acceptable (True)
|
||||
Result.set_variant_header
|
||||
end
|
||||
@@ -126,10 +125,10 @@ feature -- Media Type Negotiation
|
||||
feature -- Encoding Negotiation
|
||||
|
||||
charset_preference (a_server_charset_supported: LIST [READABLE_STRING_8]; a_header: detachable READABLE_STRING_8): CHARACTER_ENCODING_VARIANT_RESULTS
|
||||
-- `a_server_charset_supported' represent a list of charset supported by the server.
|
||||
-- `a_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.
|
||||
-- `a_server_charset_supported' represent a list of character sets supported by the server.
|
||||
-- `a_header' represents the Accept-Charset header, ie, the client preferences.
|
||||
-- Return which Charset to use in a response, if the server supports
|
||||
-- the requested Charset, or empty in other case.
|
||||
note
|
||||
EIS: "name=charset", "src=http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.2", "protocol=uri"
|
||||
local
|
||||
@@ -138,9 +137,8 @@ feature -- Encoding Negotiation
|
||||
create Result
|
||||
if a_header = Void or else a_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)
|
||||
Result.set_type (charset_default)
|
||||
else
|
||||
-- select the best match, server support, client preferences
|
||||
l_charset_match := common.best_match (a_server_charset_supported, a_header)
|
||||
@@ -150,7 +148,7 @@ feature -- Encoding Negotiation
|
||||
Result.set_supported_variants (a_server_charset_supported)
|
||||
else
|
||||
-- Set the best match
|
||||
Result.set_character_type (l_charset_match)
|
||||
Result.set_type (l_charset_match)
|
||||
Result.set_acceptable (True)
|
||||
Result.set_variant_header
|
||||
end
|
||||
@@ -162,8 +160,8 @@ feature -- Compression Negotiation
|
||||
encoding_preference (a_server_encoding_supported: LIST [READABLE_STRING_8]; a_header: detachable READABLE_STRING_8): COMPRESSION_VARIANT_RESULTS
|
||||
-- `a_server_encoding_supported' represent a list of encoding supported by the server.
|
||||
-- `a_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.
|
||||
-- Return which Encoding to use in a response, if the server supports
|
||||
-- the requested Encoding, or empty in other case.
|
||||
note
|
||||
EIS: "name=encoding", "src=http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.3", "protocol=uri"
|
||||
local
|
||||
@@ -173,7 +171,7 @@ feature -- Compression Negotiation
|
||||
if a_header = Void or else a_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)
|
||||
Result.set_type (encoding_default)
|
||||
else
|
||||
-- select the best match, server support, client preferences
|
||||
l_compression_match := common.best_match (a_server_encoding_supported, a_header)
|
||||
@@ -183,7 +181,7 @@ feature -- Compression Negotiation
|
||||
Result.set_supported_variants (a_server_encoding_supported)
|
||||
else
|
||||
-- Set the best match
|
||||
Result.set_compression_type (l_compression_match)
|
||||
Result.set_type (l_compression_match)
|
||||
Result.set_acceptable (True)
|
||||
Result.set_variant_header
|
||||
end
|
||||
@@ -195,8 +193,8 @@ feature -- Language Negotiation
|
||||
language_preference (a_server_language_supported: LIST [READABLE_STRING_8]; a_header: detachable READABLE_STRING_8): LANGUAGE_VARIANT_RESULTS
|
||||
-- `a_server_language_supported' represent a list of languages supported by the server.
|
||||
-- `a_header' represent the Accept-Language header, ie, the client preferences.
|
||||
-- Return which Language to use in a response, if the server support
|
||||
-- one Language, or empty in other case.
|
||||
-- Return which Language to use in a response, if the server supports
|
||||
-- the requested Language, or empty in other case.
|
||||
note
|
||||
EIS: "name=language", "src=http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.4", "protocol=uri"
|
||||
|
||||
@@ -207,7 +205,7 @@ feature -- Language Negotiation
|
||||
if a_header = Void or else a_header.is_empty then
|
||||
-- the request has no Accept header, ie the header is empty, in this case we use the default format
|
||||
Result.set_acceptable (TRUE)
|
||||
Result.set_language_type (language_default)
|
||||
Result.set_type (language_default)
|
||||
else
|
||||
-- select the best match, server support, client preferences
|
||||
l_language_match := language.best_match (a_server_language_supported, a_header)
|
||||
@@ -217,7 +215,7 @@ feature -- Language Negotiation
|
||||
Result.set_supported_variants (a_server_language_supported)
|
||||
else
|
||||
-- Set the best match
|
||||
Result.set_language_type (l_language_match)
|
||||
Result.set_type (l_language_match)
|
||||
Result.set_acceptable (True)
|
||||
Result.set_variant_header
|
||||
end
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
note
|
||||
description: "COMMON_ACCEPT_HEADER_PARSER, this class allows to parse Accept-Charset and Accept-Encoding headers"
|
||||
author: ""
|
||||
description: "[
|
||||
COMMON_ACCEPT_HEADER_PARSER, this class allows to parse Accept-Charset and Accept-Encoding headers
|
||||
|
||||
]"
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
EIS: "name=Charset", "src=http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.2", "protocol=uri"
|
||||
@@ -11,7 +13,7 @@ class
|
||||
|
||||
inherit {NONE}
|
||||
|
||||
STRING_UTILS
|
||||
MIME_TYPE_PARSER_UTILITIES
|
||||
|
||||
|
||||
feature -- Parser
|
||||
|
||||
@@ -1,26 +1,35 @@
|
||||
note
|
||||
description: "Summary description for {LANGUAGE_PARSE}."
|
||||
author: ""
|
||||
description: "[
|
||||
{LANGUAGE_PARSE} is encharge to parse language tags defined as follow:
|
||||
|
||||
Accept-Language = "Accept-Language" ":"
|
||||
1#( language-range [ ";" "q" "=" qvalue ] )
|
||||
language-range = ( ( 1*8ALPHA *( "-" 1*8ALPHA ) ) | "*" )
|
||||
|
||||
Example:
|
||||
Accept-Language: da, en-gb;q=0.8, en;q=0.7
|
||||
|
||||
]"
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
description: "Language Reference: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.4"
|
||||
EIS: "name=Accept-Language", "src=http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.4", "protocol=uri"
|
||||
|
||||
class
|
||||
LANGUAGE_PARSE
|
||||
|
||||
inherit {NONE}
|
||||
|
||||
STRING_UTILS
|
||||
MIME_TYPE_PARSER_UTILITIES
|
||||
|
||||
REFACTORING_HELPER
|
||||
|
||||
feature -- Parser
|
||||
|
||||
parse_mime_type (a_mime_type: READABLE_STRING_8): LANGUAGE_RESULTS
|
||||
-- Parses a mime-type into its component parts.
|
||||
-- For example, the media range 'application/xhtml;q=0.5' would get parsed
|
||||
parse_language (a_accept_language: READABLE_STRING_8): LANGUAGE_RESULTS
|
||||
-- Parses `a_accept_language' request-header field into its component parts.
|
||||
-- For example, the language range 'en-gb;q=0.8' would get parsed
|
||||
-- into:
|
||||
-- ('application', 'xhtml', {'q', '0.5'})
|
||||
-- ('en-gb', {'q':'0.8',})
|
||||
local
|
||||
l_parts: LIST [READABLE_STRING_8]
|
||||
p: READABLE_STRING_8
|
||||
@@ -31,7 +40,7 @@ feature -- Parser
|
||||
do
|
||||
fixme ("Improve code!!!")
|
||||
create Result.make
|
||||
l_parts := a_mime_type.split (';')
|
||||
l_parts := a_accept_language.split (';')
|
||||
from
|
||||
i := 1
|
||||
until
|
||||
@@ -44,8 +53,6 @@ feature -- Parser
|
||||
end
|
||||
i := i + 1
|
||||
end
|
||||
--Java URLConnection class sends an Accept header that includes a
|
||||
--single "*" - Turn it into a legal wildcard.
|
||||
|
||||
l_full_type := trim (l_parts [1])
|
||||
if l_full_type.same_string ("*") then
|
||||
@@ -60,16 +67,16 @@ feature -- Parser
|
||||
end
|
||||
end
|
||||
|
||||
parse_media_range (a_range: READABLE_STRING_8): LANGUAGE_RESULTS
|
||||
-- Media-ranges are mime-types with wild-cards and a 'q' quality parameter.
|
||||
-- For example, the media range 'application/*;q=0.5' would get parsed into:
|
||||
-- ('application', '*', {'q', '0.5'})
|
||||
parse_language_range (a_language_range: READABLE_STRING_8): LANGUAGE_RESULTS
|
||||
-- Languages-ranges are languages with wild-cards and a 'q' quality parameter.
|
||||
-- For example, the language range ('en-* ;q=0.5') would get parsed into:
|
||||
-- ('en', '*', {'q', '0.5'})
|
||||
-- In addition this function also guarantees that there is a value for 'q'
|
||||
-- in the params dictionary, filling it in with a proper default if
|
||||
-- necessary.
|
||||
do
|
||||
fixme ("Improve the code!!!")
|
||||
Result := parse_mime_type (a_range)
|
||||
Result := parse_language (a_language_range)
|
||||
if attached Result.item ("q") as q then
|
||||
if q.is_double and then attached {REAL_64} q.to_double as r and then (r >= 0.0 and r <= 1.0) then
|
||||
--| Keep current value
|
||||
@@ -85,12 +92,9 @@ feature -- Parser
|
||||
end
|
||||
end
|
||||
|
||||
fitness_and_quality_parsed (a_mime_type: READABLE_STRING_8; parsed_ranges: LIST [LANGUAGE_RESULTS]): FITNESS_AND_QUALITY
|
||||
-- Find the best match for a given mimeType against a list of media_ranges
|
||||
-- that have already been parsed by parse_media_range. Returns a
|
||||
-- tuple of the fitness value and the value of the 'q' quality parameter of
|
||||
-- the best match, or (-1, 0) if no match was found. Just as for
|
||||
-- quality_parsed(), 'parsed_ranges' must be a list of parsed media ranges.
|
||||
fitness_and_quality_parsed (a_language: READABLE_STRING_8; a_parsed_ranges: LIST [LANGUAGE_RESULTS]): FITNESS_AND_QUALITY
|
||||
-- Find the best match for a given `a_language' against a list of language ranges `a_parsed_ranges'
|
||||
-- that have already been parsed by parse_language_range.
|
||||
local
|
||||
best_fitness: INTEGER
|
||||
target_q: REAL_64
|
||||
@@ -104,7 +108,7 @@ feature -- Parser
|
||||
do
|
||||
best_fitness := -1
|
||||
best_fit_q := 0.0
|
||||
target := parse_media_range (a_mime_type)
|
||||
target := parse_language_range (a_language)
|
||||
if attached target.item ("q") as q and then q.is_double then
|
||||
target_q := q.to_double
|
||||
if target_q < 0.0 then
|
||||
@@ -117,11 +121,11 @@ feature -- Parser
|
||||
end
|
||||
if attached target.type as l_target_type then
|
||||
from
|
||||
parsed_ranges.start
|
||||
a_parsed_ranges.start
|
||||
until
|
||||
parsed_ranges.after
|
||||
a_parsed_ranges.after
|
||||
loop
|
||||
range := parsed_ranges.item_for_iteration
|
||||
range := a_parsed_ranges.item_for_iteration
|
||||
if (attached range.type as l_range_type and then (l_target_type.same_string (l_range_type) or l_range_type.same_string ("*") or l_target_type.same_string ("*"))) then
|
||||
from
|
||||
param_matches := 0
|
||||
@@ -157,46 +161,46 @@ feature -- Parser
|
||||
end
|
||||
end
|
||||
end
|
||||
parsed_ranges.forth
|
||||
a_parsed_ranges.forth
|
||||
end
|
||||
end
|
||||
create Result.make (best_fitness, best_fit_q)
|
||||
end
|
||||
|
||||
quality_parsed (a_mime_type: READABLE_STRING_8; parsed_ranges: LIST [LANGUAGE_RESULTS]): REAL_64
|
||||
-- Find the best match for a given mime-type against a list of ranges that
|
||||
-- have already been parsed by parseMediaRange(). Returns the 'q' quality
|
||||
quality_parsed (a_language: READABLE_STRING_8; a_parsed_ranges: LIST [LANGUAGE_RESULTS]): REAL_64
|
||||
-- Find the best match for a given `a_language' against a list of ranges `parsed_ranges' that
|
||||
-- have already been parsed by parse_language_range. Returns the 'q' quality
|
||||
-- parameter of the best match, 0 if no match was found. This function
|
||||
-- bahaves the same as quality() except that 'parsed_ranges' must be a list
|
||||
-- of parsed media ranges.
|
||||
-- bahaves the same as quality except that 'a_parsed_ranges' must be a list
|
||||
-- of parsed language ranges.
|
||||
do
|
||||
Result := fitness_and_quality_parsed (a_mime_type, parsed_ranges).quality
|
||||
Result := fitness_and_quality_parsed (a_language, a_parsed_ranges).quality
|
||||
end
|
||||
|
||||
quality (a_mime_type: READABLE_STRING_8; ranges: READABLE_STRING_8): REAL_64
|
||||
-- Returns the quality 'q' of a mime-type when compared against the
|
||||
-- mediaRanges in ranges.
|
||||
quality (a_language: READABLE_STRING_8; a_ranges: READABLE_STRING_8): REAL_64
|
||||
-- Returns the quality 'q' of a `a_language' when compared against the
|
||||
-- language range in `a_ranges'.
|
||||
local
|
||||
l_ranges: LIST [READABLE_STRING_8]
|
||||
res: ARRAYED_LIST [LANGUAGE_RESULTS]
|
||||
p_res: LANGUAGE_RESULTS
|
||||
do
|
||||
l_ranges := ranges.split (',')
|
||||
l_ranges := a_ranges.split (',')
|
||||
from
|
||||
create res.make (10);
|
||||
l_ranges.start
|
||||
until
|
||||
l_ranges.after
|
||||
loop
|
||||
p_res := parse_media_range (l_ranges.item_for_iteration)
|
||||
p_res := parse_language_range (l_ranges.item_for_iteration)
|
||||
res.put_left (p_res)
|
||||
l_ranges.forth
|
||||
end
|
||||
Result := quality_parsed (a_mime_type, res)
|
||||
Result := quality_parsed (a_language, res)
|
||||
end
|
||||
|
||||
best_match (supported: LIST [READABLE_STRING_8]; header: READABLE_STRING_8): READABLE_STRING_8
|
||||
-- Choose the mime-type with the highest fitness score and quality ('q') from a list of candidates.
|
||||
best_match (a_supported: LIST [READABLE_STRING_8]; a_header: READABLE_STRING_8): READABLE_STRING_8
|
||||
-- Choose the `language' with the highest fitness score and quality ('q') from a list of candidates.
|
||||
local
|
||||
l_header_results: LIST [LANGUAGE_RESULTS]
|
||||
weighted_matches: LIST [FITNESS_AND_QUALITY]
|
||||
@@ -205,7 +209,7 @@ feature -- Parser
|
||||
fitness_and_quality, first_one: detachable FITNESS_AND_QUALITY
|
||||
s: READABLE_STRING_8
|
||||
do
|
||||
l_res := header.split (',')
|
||||
l_res := a_header.split (',')
|
||||
create {ARRAYED_LIST [LANGUAGE_RESULTS]} l_header_results.make (l_res.count)
|
||||
fixme ("Extract method!!!")
|
||||
from
|
||||
@@ -213,20 +217,20 @@ feature -- Parser
|
||||
until
|
||||
l_res.after
|
||||
loop
|
||||
p_res := parse_media_range (l_res.item_for_iteration)
|
||||
p_res := parse_language_range (l_res.item_for_iteration)
|
||||
l_header_results.force (p_res)
|
||||
l_res.forth
|
||||
end
|
||||
create {ARRAYED_LIST [FITNESS_AND_QUALITY]} weighted_matches.make (supported.count)
|
||||
create {ARRAYED_LIST [FITNESS_AND_QUALITY]} weighted_matches.make (a_supported.count)
|
||||
from
|
||||
supported.start
|
||||
a_supported.start
|
||||
until
|
||||
supported.after
|
||||
a_supported.after
|
||||
loop
|
||||
fitness_and_quality := fitness_and_quality_parsed (supported.item_for_iteration, l_header_results)
|
||||
fitness_and_quality.set_mime_type (mime_type (supported.item_for_iteration))
|
||||
fitness_and_quality := fitness_and_quality_parsed (a_supported.item_for_iteration, l_header_results)
|
||||
fitness_and_quality.set_mime_type (mime_type (a_supported.item_for_iteration))
|
||||
weighted_matches.force (fitness_and_quality)
|
||||
supported.forth
|
||||
a_supported.forth
|
||||
end
|
||||
|
||||
--| Keep only top quality+fitness types
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
note
|
||||
description: "Summary description for {MIME_PARSE}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
EIS: "name=Accept", "src=http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1", "protocol=uri"
|
||||
|
||||
class
|
||||
MIME_PARSE
|
||||
|
||||
inherit {NONE}
|
||||
|
||||
STRING_UTILS
|
||||
MIME_TYPE_PARSER_UTILITIES
|
||||
|
||||
REFACTORING_HELPER
|
||||
|
||||
|
||||
@@ -1,28 +1,29 @@
|
||||
note
|
||||
description: "Summary description for {STRING_UTILS}."
|
||||
author: ""
|
||||
description: "{MIME_TYPE_PARSER_UTILITIES}."
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
STRING_UTILS
|
||||
MIME_TYPE_PARSER_UTILITIES
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
mime_type (s: READABLE_STRING_8): READABLE_STRING_8
|
||||
mime_type (a_str: READABLE_STRING_8): READABLE_STRING_8
|
||||
-- `s' with any trailing parameters stripped
|
||||
local
|
||||
p: INTEGER
|
||||
do
|
||||
p := s.index_of (';', 1)
|
||||
p := a_str.index_of (';', 1)
|
||||
if p > 0 then
|
||||
Result := trim (s.substring (1, p - 1))
|
||||
Result := trim (a_str.substring (1, p - 1))
|
||||
else
|
||||
Result := trim (s.string)
|
||||
Result := trim (a_str.string)
|
||||
end
|
||||
end
|
||||
|
||||
trim (a_string: READABLE_STRING_8): READABLE_STRING_8
|
||||
-- trim whitespace from the beginning and end of a string
|
||||
-- `a_string'
|
||||
require
|
||||
valid_argument : a_string /= Void
|
||||
local
|
||||
@@ -1,6 +1,5 @@
|
||||
note
|
||||
description: "Summary description for {COMMON_RESULTS}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
@@ -62,7 +61,7 @@ feature -- Element change
|
||||
do
|
||||
field := a_field
|
||||
ensure
|
||||
field_assigned: field /= Void implies field = a_field
|
||||
field_set: attached field as l_field implies l_field = a_field
|
||||
end
|
||||
|
||||
put (new: STRING; key: STRING)
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
note
|
||||
description: "Summary description for {LANGUAGE_RESULTS}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
note
|
||||
description: "Summary description for {PARSE_RESULTS}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
note
|
||||
description: "Summary description for {CHARACTER_ENCODING_VARIANT_RESULTS}."
|
||||
author: ""
|
||||
description: "[
|
||||
{CHARACTER_ENCODING_VARIANT_RESULTS}
|
||||
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.
|
||||
]"
|
||||
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
@@ -10,21 +15,10 @@ class
|
||||
inherit
|
||||
|
||||
VARIANT_RESULTS
|
||||
|
||||
feature -- Access
|
||||
|
||||
character_type: detachable READABLE_STRING_8
|
||||
|
||||
|
||||
feature -- Change Element
|
||||
|
||||
set_character_type (a_character_type: READABLE_STRING_8)
|
||||
-- Set `character_type' with `a_character_type'
|
||||
do
|
||||
character_type := a_character_type
|
||||
ensure
|
||||
character_type_set: character_type /= Void implies a_character_type = character_type
|
||||
end
|
||||
|
||||
set_variant_header
|
||||
-- Set variant header as `Accept-Charset'
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
note
|
||||
description: "Summary description for {COMPRESSION_VARIANT_RESULTS}."
|
||||
author: ""
|
||||
description: "[
|
||||
{COMPRESSION_VARIANT_RESULTS}
|
||||
Represent the compression results between client preferences and ccompression 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
|
||||
]"
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
EIS: "name= Compression", "src=http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.3", "protocol=uri"
|
||||
@@ -11,23 +15,10 @@ class
|
||||
inherit
|
||||
|
||||
VARIANT_RESULTS
|
||||
|
||||
feature -- Access
|
||||
|
||||
compression_type: detachable READABLE_STRING_8
|
||||
-- Compression variant for the response
|
||||
|
||||
|
||||
feature -- Change Element
|
||||
|
||||
set_compression_type (a_compression_type: READABLE_STRING_8)
|
||||
-- Set `compression_type' with `a_compression_type'
|
||||
do
|
||||
compression_type := a_compression_type
|
||||
ensure
|
||||
compression_type_set: attached compression_type as l_compression_type implies l_compression_type = a_compression_type
|
||||
end
|
||||
|
||||
set_variant_header
|
||||
-- Set variant_header as `Accept-Encoding'
|
||||
do
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
note
|
||||
description: "Summary description for {LANGUAGE_VARIANT_RESULTS}."
|
||||
author: ""
|
||||
description: "[
|
||||
{LANGUAGE_VARIANT_RESULTS}.
|
||||
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
|
||||
]"
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
@@ -11,22 +15,10 @@ inherit
|
||||
|
||||
VARIANT_RESULTS
|
||||
|
||||
feature -- Access
|
||||
|
||||
language_type: detachable READABLE_STRING_8
|
||||
-- language variant for the response
|
||||
|
||||
feature -- Change Element
|
||||
|
||||
|
||||
set_language_type (a_language_type: READABLE_STRING_8)
|
||||
-- Set `language_type' with `a_language_type'
|
||||
do
|
||||
language_type := a_language_type
|
||||
ensure
|
||||
language_type_set: attached language_type as l_language_type implies l_language_type = a_language_type
|
||||
end
|
||||
|
||||
set_variant_header
|
||||
-- Set variant header as 'Accept-Language'
|
||||
do
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
note
|
||||
description: "Summary description for {MEDIA_TYPE_VARIANT_RESULTS}."
|
||||
author: ""
|
||||
description: "[
|
||||
{MEDIA_TYPE_VARIANT_RESULTS}.
|
||||
Represent 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
|
||||
]"
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
@@ -11,20 +15,9 @@ inherit
|
||||
|
||||
VARIANT_RESULTS
|
||||
|
||||
feature -- Access
|
||||
|
||||
media_type: detachable READABLE_STRING_8
|
||||
|
||||
feature -- Change Element
|
||||
|
||||
set_media_type (a_media_type: READABLE_STRING_8)
|
||||
-- Set `media_type' as `a_media_type'
|
||||
do
|
||||
media_type := a_media_type
|
||||
ensure
|
||||
media_type_set: attached media_type as l_media_type implies l_media_type = a_media_type
|
||||
end
|
||||
|
||||
set_variant_header
|
||||
-- Set variant header as `Accept'
|
||||
do
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
note
|
||||
description: "Summary description for {VARIANT_RESULTS}."
|
||||
author: ""
|
||||
description: "Generic {VARIANT_RESULTS}.with common functionality to most header variants.."
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
@@ -10,7 +9,7 @@ deferred class
|
||||
feature -- Access
|
||||
|
||||
variant_header: detachable READABLE_STRING_8
|
||||
-- variant header for the response
|
||||
-- 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
|
||||
@@ -18,6 +17,11 @@ feature -- Access
|
||||
is_acceptable: BOOLEAN
|
||||
-- is the current variant accepted?
|
||||
|
||||
type: detachable READABLE_STRING_8
|
||||
-- the type could be: media type, language, chracter_sets and encoding.
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
accept_headers_set: ARRAY[READABLE_STRING_8]
|
||||
-- Set of valid accept headers headers
|
||||
note
|
||||
@@ -40,6 +44,15 @@ feature -- Status_Report
|
||||
|
||||
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
|
||||
@@ -48,7 +61,6 @@ feature -- Change Element
|
||||
is_acceptable_set: is_acceptable = acceptable
|
||||
end
|
||||
|
||||
|
||||
set_variant_header
|
||||
-- Set variant header
|
||||
deferred
|
||||
@@ -57,7 +69,7 @@ feature -- Change Element
|
||||
end
|
||||
|
||||
set_supported_variants (a_supported: LIST [READABLE_STRING_8])
|
||||
-- Set `supported vairants' with `a_supported'
|
||||
-- Set `supported variants' with `a_supported'
|
||||
do
|
||||
supported_variants := a_supported
|
||||
ensure
|
||||
|
||||
@@ -78,10 +78,10 @@ feature {NONE} -- Initialization
|
||||
print (language.best_match (accept.split (','), "da"))
|
||||
print (language.best_match (accept.split (','), "en-*"))
|
||||
|
||||
print ("%N"+language.parse_media_range ("da").out)
|
||||
print ("%N"+language.parse_media_range ("en-gb;q=0.8").out)
|
||||
print ("%N"+language.parse_media_range ("en;q=0.7").out)
|
||||
print ("%N"+language.parse_media_range ("en-*").out)
|
||||
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
|
||||
|
||||
@@ -36,13 +36,13 @@ feature -- Test routines
|
||||
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.media_type = 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.media_type))
|
||||
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
|
||||
@@ -50,7 +50,7 @@ feature -- Test routines
|
||||
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.media_type.is_equal ("application/json"))
|
||||
assert ("Media Type is application/json", media_variants.type.is_equal ("application/json"))
|
||||
|
||||
end
|
||||
|
||||
@@ -70,14 +70,14 @@ feature -- Test routines
|
||||
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.character_type = 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.character_type))
|
||||
assert ("Charset is defaul", conneg.charset_default.is_equal (charset_variants.type))
|
||||
assert ("Variant header", charset_variants.variant_header = Void)
|
||||
|
||||
|
||||
@@ -86,7 +86,7 @@ feature -- Test routines
|
||||
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.character_type.is_equal ("iso-8859-5"))
|
||||
assert ("Character Type is iso-8859-5", charset_variants.type.is_equal ("iso-8859-5"))
|
||||
end
|
||||
|
||||
test_compression_negotiation
|
||||
@@ -103,14 +103,14 @@ feature -- Test routines
|
||||
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.compression_type = 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.compression_type))
|
||||
assert ("Compression is defaul", conneg.encoding_default.is_equal (compression_variants.type))
|
||||
assert ("Variant header", compression_variants.variant_header = Void)
|
||||
|
||||
|
||||
@@ -122,7 +122,7 @@ feature -- Test routines
|
||||
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.compression_type.is_equal ("gzip"))
|
||||
assert ("Encoding Type is gzip", compression_variants.type.is_equal ("gzip"))
|
||||
end
|
||||
|
||||
|
||||
@@ -141,14 +141,14 @@ feature -- Test routines
|
||||
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.language_type = 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.language_type))
|
||||
assert ("Language is defaul", conneg.language_default.is_equal (language_variants.type))
|
||||
assert ("Variant header", language_variants.variant_header = Void)
|
||||
|
||||
|
||||
@@ -157,7 +157,7 @@ feature -- Test routines
|
||||
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.language_type.is_equal ("fr"))
|
||||
assert ("Language Type is fr", language_variants.type.is_equal ("fr"))
|
||||
|
||||
|
||||
end
|
||||
|
||||
@@ -25,10 +25,10 @@ feature -- Test routines
|
||||
|
||||
test_parse_media_range
|
||||
do
|
||||
assert ("Expected ('da', {'q':'1.0',})", parser.parse_media_range ("da").out.same_string ("('da', {'q':'1.0',})"));
|
||||
assert ("Expected ('en', 'gb', {'q':'0.8',})", parser.parse_media_range ("en-gb;q=0.8").out.same_string ("('en', 'gb', {'q':'0.8',})"));
|
||||
assert ("Expected ('en', {'q':'0.7',})", parser.parse_media_range ("en;q=0.7").out.same_string ("('en', {'q':'0.7',})"));
|
||||
assert ("Expected ('en', '*', {'q':'1.0',})", parser.parse_media_range ("en-*").out.same_string ("('en', '*', {'q':'1.0',})"));
|
||||
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
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user