Reviewed WSF_REQUEST.item (..) and items to look into Form, Query, and Path (cookie are excluded for security)

Added WSF_REQUEST.path_parameter (a_name): detachable WSF_VALUE
   - fill path_parameters using `import_raw_path_parameters"
     when executing the route
   - reset to previous value with reset_path_parameters (..),
     just in case the request is executed via severals routes.
This commit is contained in:
Jocelyn Fiat
2012-05-07 23:16:52 +02:00
parent e615026520
commit 278a71eaaf
5 changed files with 118 additions and 52 deletions

View File

@@ -26,6 +26,18 @@ feature {NONE} -- Initialization
path := p path := p
end end
feature -- Request data
apply (req: WSF_REQUEST)
-- <Precursor>
do
end
revert (req: WSF_REQUEST)
-- <Precursor>
do
end
feature -- Item feature -- Item
item (a_name: READABLE_STRING_32): detachable WSF_VALUE item (a_name: READABLE_STRING_32): detachable WSF_VALUE

View File

@@ -43,6 +43,24 @@ feature -- Access
uri_template_match: URI_TEMPLATE_MATCH_RESULT uri_template_match: URI_TEMPLATE_MATCH_RESULT
feature -- Environment
old_path_parameters: detachable ITERABLE [WSF_VALUE]
apply (req: WSF_REQUEST)
-- <Precursor>
do
old_path_parameters := req.path_parameters
req.import_raw_path_parameters (uri_template_match.path_variables)
end
revert (req: WSF_REQUEST)
-- <Precursor>
do
if attached old_path_parameters as vals then
req.reset_path_parameters (vals)
end
end
feature -- Item feature -- Item

View File

@@ -27,6 +27,20 @@ feature -- Access
path: READABLE_STRING_8 path: READABLE_STRING_8
-- Associated path -- Associated path
feature -- Request data
apply (req: WSF_REQUEST)
-- Apply current data to request `req'
--| mainly to fill {WSF_REQUEST}.path_parameters
deferred
end
revert (req: WSF_REQUEST)
-- Revert potential previous `apply' for request `req'
--| mainly to restore previous {WSF_REQUEST}.path_parameters
deferred
end
feature -- Url Query feature -- Url Query
script_absolute_url (a_path: STRING): STRING script_absolute_url (a_path: STRING): STRING

View File

@@ -144,9 +144,16 @@ feature -- Execution
-- Process route `a_route' -- Process route `a_route'
require require
a_route_attached: a_route /= Void a_route_attached: a_route /= Void
local
ctx: C
do do
pre_route_execution_actions.call ([a_route]) pre_route_execution_actions.call ([a_route])
a_route.handler.execute (a_route.context, req, res) ctx := a_route.context
ctx.apply (req)
a_route.handler.execute (ctx, req, res)
ctx.revert (req)
rescue
a_route.context.revert (req)
end end
dispatch (req: WSF_REQUEST; res: WSF_RESPONSE): BOOLEAN dispatch (req: WSF_REQUEST; res: WSF_RESPONSE): BOOLEAN

View File

@@ -56,6 +56,9 @@ feature {NONE} -- Initialization
set_raw_input_data_recorded (False) set_raw_input_data_recorded (False)
create {STRING_32} empty_string.make_empty create {STRING_32} empty_string.make_empty
create path_parameters_table.make (0)
path_parameters_table.compare_objects
create execution_variables_table.make (0) create execution_variables_table.make (0)
execution_variables_table.compare_objects execution_variables_table.compare_objects
@@ -200,7 +203,7 @@ feature -- Eiffel WGI access
feature {NONE} -- Access: global variable feature {NONE} -- Access: global variable
items_table: HASH_TABLE [WSF_VALUE, READABLE_STRING_8] items_table: HASH_TABLE [WSF_VALUE, READABLE_STRING_32]
-- Table containing all the various variables -- Table containing all the various variables
-- Warning: this is computed each time, if you change the content of other containers -- Warning: this is computed each time, if you change the content of other containers
-- this won't update this Result's content, unless you query it again -- this won't update this Result's content, unless you query it again
@@ -208,7 +211,7 @@ feature {NONE} -- Access: global variable
create Result.make (100) create Result.make (100)
across across
meta_variables as vars path_parameters as vars
loop loop
Result.force (vars.item, vars.item.name) Result.force (vars.item, vars.item.name)
end end
@@ -224,12 +227,6 @@ feature {NONE} -- Access: global variable
loop loop
Result.force (vars.item, vars.item.name) Result.force (vars.item, vars.item.name)
end end
across
cookies as vars
loop
Result.force (vars.item, vars.item.name)
end
end end
feature -- Access: global variable feature -- Access: global variable
@@ -241,22 +238,19 @@ feature -- Access: global variable
item (a_name: READABLE_STRING_32): detachable WSF_VALUE item (a_name: READABLE_STRING_32): detachable WSF_VALUE
-- Variable named `a_name' from any of the variables container -- Variable named `a_name' from any of the variables container
-- and following a specific order -- and following a specific order: form_, query_ and path_ parameters
-- execution, environment, get, post, cookies --| Cookie are not included due to security reason.
do do
Result := meta_variable (a_name) Result := form_parameter (a_name)
if Result = Void then if Result = Void then
Result := query_parameter (a_name) Result := query_parameter (a_name)
if Result = Void then if Result = Void then
Result := form_parameter (a_name) Result := path_parameter (a_name)
if Result = Void then
Result := cookie (a_name)
end
end end
end end
end end
string_item (a_name: READABLE_STRING_8): detachable READABLE_STRING_32 string_item (a_name: READABLE_STRING_32): detachable READABLE_STRING_32
do do
if attached {WSF_STRING} item (a_name) as val then if attached {WSF_STRING} item (a_name) as val then
Result := val.string Result := val.string
@@ -267,7 +261,7 @@ feature -- Access: global variable
feature -- Execution variables feature -- Execution variables
execution_variable (a_name: READABLE_STRING_8): detachable ANY execution_variable (a_name: READABLE_STRING_32): detachable ANY
-- Execution variable related to `a_name' -- Execution variable related to `a_name'
require require
a_name_valid: a_name /= Void and then not a_name.is_empty a_name_valid: a_name /= Void and then not a_name.is_empty
@@ -898,6 +892,61 @@ feature {NONE} -- Cookies
Result := l_cookies Result := l_cookies
end end
feature -- Path parameters
path_parameters: ITERABLE [WSF_VALUE]
do
Result := path_parameters_table
end
path_parameter (a_name: READABLE_STRING_32): detachable WSF_VALUE
-- Parameter for name `n'.
do
Result := path_parameters_table.item (a_name)
end
feature -- Path parameters: Element change
import_raw_path_parameters (lst: detachable TABLE_ITERABLE [READABLE_STRING_8, READABLE_STRING_8])
-- The `path_parameters' are filled when known during the request handling
-- with table of urlencoded values
local
l_table: like path_parameters_table
do
create l_table.make (3)
path_parameters_table := l_table
-- Remove existing previous values
l_table.wipe_out
if lst /= Void then
across
lst as c
loop
add_value_to_table (c.key, c.item, l_table)
end
end
end
reset_path_parameters (vars: detachable like path_parameters)
local
l_table: like path_parameters_table
do
l_table := path_parameters_table
l_table.wipe_out
if vars /= Void then
across
vars as c
loop
l_table.force (c.item, c.item.name)
end
end
end
feature {NONE} -- Query parameters: implementation
path_parameters_table: HASH_TABLE [WSF_VALUE, READABLE_STRING_32]
-- Variables extracted from QUERY_STRING
feature -- Query parameters feature -- Query parameters
query_parameters: ITERABLE [WSF_VALUE] query_parameters: ITERABLE [WSF_VALUE]
@@ -1410,40 +1459,6 @@ feature {WSF_MIME_HANDLER} -- Temporary File handling
retry retry
end end
feature {WSF_MIME_HANDLER} -- Input data access
form_input_data (nb: NATURAL_64): READABLE_STRING_8
-- All data from input form
local
nb32: INTEGER
n64: NATURAL_64
n: INTEGER
t: STRING
s: STRING_8
do
from
n64 := nb
nb32 := n64.to_integer_32
create s.make (nb32)
Result := s
n := nb32
if n > 1_024 then
n := 1_024
end
until
n64 <= 0
loop
input.read_string (n)
t := input.last_string
s.append_string (t)
if t.count < n then
n64 := 0
else
n64 := n64 - t.count.as_natural_64
end
end
end
feature {NONE} -- Internal value feature {NONE} -- Internal value
internal_query_parameters_table: detachable like query_parameters_table internal_query_parameters_table: detachable like query_parameters_table