Rather use (READABLE_)STRING_GENERAL for argument instead of _8 or _32 variant

Better design to set the WSF_REQUEST.path_parameters
   especially handle the case where the request goes trought more than one route (could be the case when using WSF_ROUTING_HANDLER)
This commit is contained in:
Jocelyn Fiat
2012-05-14 18:12:28 +02:00
parent 64eebd32db
commit c3c27c5027
9 changed files with 302 additions and 216 deletions

View File

@@ -40,7 +40,7 @@ feature -- Request data
feature -- Item
item (a_name: READABLE_STRING_32): detachable WSF_VALUE
item (a_name: READABLE_STRING_GENERAL): detachable WSF_VALUE
-- Variable value for parameter or variable `a_name'
-- See `{WSF_REQUEST}.item(s)'
do

View File

@@ -24,6 +24,8 @@ inherit
item
end
WSF_REQUEST_PATH_PARAMETERS_SOURCE
create
make
@@ -45,30 +47,40 @@ feature -- Access
feature -- Environment
old_path_parameters: detachable ITERABLE [WSF_VALUE]
path_parameters_count: INTEGER
do
Result := uri_template_match.path_variables.count
end
urlencoded_path_parameters: TABLE_ITERABLE [READABLE_STRING_8, READABLE_STRING_8]
-- <Precursor>
do
Result := uri_template_match.path_variables
end
previous_path_parameters_source: detachable WSF_REQUEST_PATH_PARAMETERS_SOURCE
apply (req: WSF_REQUEST)
-- <Precursor>
do
old_path_parameters := req.path_parameters
req.import_raw_path_parameters (uri_template_match.path_variables)
previous_path_parameters_source := req.path_parameters_source
req.set_path_parameters_source (Current)
end
revert (req: WSF_REQUEST)
-- <Precursor>
do
if attached old_path_parameters as vals then
req.reset_path_parameters (vals)
end
req.set_path_parameters_source (previous_path_parameters_source)
previous_path_parameters_source := Void
end
feature -- Item
item (a_name: READABLE_STRING_32): detachable WSF_VALUE
item (a_name: READABLE_STRING_GENERAL): detachable WSF_VALUE
-- Variable value for parameter or variable `a_name'
-- See `{WSF_REQUEST}.item(s)'
do
Result := path_parameter (a_name.as_string_8) --| Should we handle url-encoded name?
Result := path_parameter (a_name) --| Should we handle url-encoded name?
if Result = Void then
Result := request.item (a_name)
end
@@ -76,20 +88,23 @@ feature -- Item
feature -- Path parameter
path_parameter (a_name: READABLE_STRING_8): detachable WSF_VALUE
path_parameter (a_name: READABLE_STRING_GENERAL): detachable WSF_VALUE
local
n: READABLE_STRING_8
do
if attached uri_template_match.url_decoded_path_variable (a_name) as s then
create {WSF_STRING} Result.make (a_name, s)
n := uri_template_match.encoded_name (a_name)
if attached uri_template_match.path_variable (n) as s then
create {WSF_STRING} Result.make (n, s)
end
end
is_integer_path_parameter (a_name: READABLE_STRING_8): BOOLEAN
is_integer_path_parameter (a_name: READABLE_STRING_GENERAL): BOOLEAN
-- Is path parameter related to `a_name' an integer value?
do
Result := attached string_path_parameter (a_name) as s and then s.is_integer
end
integer_path_parameter (a_name: READABLE_STRING_8): INTEGER
integer_path_parameter (a_name: READABLE_STRING_GENERAL): INTEGER
-- Integer value for path parameter `a_name' if relevant.
require
is_integer_path_parameter: is_integer_path_parameter (a_name)
@@ -97,13 +112,13 @@ feature -- Path parameter
Result := integer_from (path_parameter (a_name))
end
string_path_parameter (a_name: READABLE_STRING_8): detachable READABLE_STRING_32
string_path_parameter (a_name: READABLE_STRING_GENERAL): detachable READABLE_STRING_32
-- String value for path parameter `a_name' if relevant.
do
Result := string_from (path_parameter (a_name))
end
string_array_path_parameter (a_name: READABLE_STRING_8): detachable ARRAY [READABLE_STRING_32]
string_array_path_parameter (a_name: READABLE_STRING_GENERAL): detachable ARRAY [READABLE_STRING_32]
-- Array of string values for path parameter `a_name' if relevant.
do
Result := string_array_for (a_name, agent string_path_parameter)

View File

@@ -19,6 +19,8 @@ inherit
{NONE} all
end
DEBUG_OUTPUT
feature -- Access
request: WSF_REQUEST
@@ -125,7 +127,7 @@ feature -- Query
feature -- Item
item (a_name: READABLE_STRING_32): detachable WSF_VALUE
item (a_name: READABLE_STRING_GENERAL): detachable WSF_VALUE
-- Variable value for parameter or variable `a_name'
-- See `{WSF_REQUEST}.item(s)'
deferred
@@ -133,13 +135,13 @@ feature -- Item
feature -- Parameter
string_item (a_name: READABLE_STRING_8): detachable READABLE_STRING_32
string_item (a_name: READABLE_STRING_GENERAL): detachable READABLE_STRING_32
-- String value for any variable of parameter `a_name' if relevant.
do
Result := string_from (item (a_name))
end
string_array_item (a_name: READABLE_STRING_8): detachable ARRAY [READABLE_STRING_32]
string_array_item (a_name: READABLE_STRING_GENERAL): detachable ARRAY [READABLE_STRING_32]
-- Array of string values for query parameter `a_name' if relevant.
do
Result := string_array_for (a_name, agent string_item)
@@ -147,32 +149,32 @@ feature -- Parameter
feature -- Query parameter
query_parameter (a_name: READABLE_STRING_8): detachable WSF_VALUE
query_parameter (a_name: READABLE_STRING_GENERAL): detachable WSF_VALUE
-- Parameter value for query variable `a_name'
--| i.e after the ? character
do
Result := request.query_parameter (a_name)
end
string_query_parameter (a_name: READABLE_STRING_8): detachable READABLE_STRING_32
string_query_parameter (a_name: READABLE_STRING_GENERAL): detachable READABLE_STRING_32
-- String value for query parameter `a_name' if relevant.
do
Result := string_from (query_parameter (a_name))
end
string_array_query_parameter (a_name: READABLE_STRING_8): detachable ARRAY [READABLE_STRING_32]
string_array_query_parameter (a_name: READABLE_STRING_GENERAL): detachable ARRAY [READABLE_STRING_32]
-- Array of string values for query parameter `a_name' if relevant.
do
Result := string_array_for (a_name, agent string_query_parameter)
end
is_integer_query_parameter (a_name: READABLE_STRING_8): BOOLEAN
is_integer_query_parameter (a_name: READABLE_STRING_GENERAL): BOOLEAN
-- Is query parameter related to `a_name' an integer value?
do
Result := attached string_query_parameter (a_name) as s and then s.is_integer
end
integer_query_parameter (a_name: READABLE_STRING_8): INTEGER
integer_query_parameter (a_name: READABLE_STRING_GENERAL): INTEGER
-- Integer value for query parameter `a_name' if relevant.
require
is_integer_query_parameter: is_integer_query_parameter (a_name)
@@ -202,7 +204,7 @@ feature -- Convertion
feature {NONE} -- Implementation
string_array_for (a_name: READABLE_STRING_8; a_item_fct: FUNCTION [ANY, TUPLE [READABLE_STRING_8], detachable READABLE_STRING_32]): detachable ARRAY [READABLE_STRING_32]
string_array_for (a_name: READABLE_STRING_GENERAL; a_item_fct: FUNCTION [ANY, TUPLE [READABLE_STRING_GENERAL], detachable READABLE_STRING_32]): detachable ARRAY [READABLE_STRING_32]
-- Array of string values for query parameter `a_name' if relevant.
local
i: INTEGER
@@ -226,6 +228,14 @@ feature {NONE} -- Implementation
Result.keep_head (n - 1)
end
feature -- Status report
debug_output: STRING
-- String that should be displayed in debugger to represent `Current'.
do
Result := path
end
;note
copyright: "2011-2012, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"