Refactored wsf router dispatching implementation.
Now the path to take into account during dispatching is computed once in WSF_ROUTER.path_to_dispatch (req: WSF_REQUEST): READABLE_STRING_8 And this function could be redefined in descendant of WSF_ROUTER.
This commit is contained in:
@@ -47,26 +47,22 @@ feature -- Documentation
|
|||||||
|
|
||||||
feature -- Status
|
feature -- Status
|
||||||
|
|
||||||
is_mapping (req: WSF_REQUEST; a_router: WSF_ROUTER): BOOLEAN
|
is_mapping (a_path: READABLE_STRING_8; req: WSF_REQUEST; a_router: WSF_ROUTER): BOOLEAN
|
||||||
-- <Precursor>
|
-- <Precursor>
|
||||||
local
|
local
|
||||||
p: READABLE_STRING_8
|
|
||||||
s: like based_uri
|
s: like based_uri
|
||||||
do
|
do
|
||||||
p := path_from_request (req)
|
|
||||||
s := based_uri (uri, a_router)
|
s := based_uri (uri, a_router)
|
||||||
Result := p.starts_with (s)
|
Result := a_path.starts_with (s)
|
||||||
end
|
end
|
||||||
|
|
||||||
try (req: WSF_REQUEST; res: WSF_RESPONSE; sess: WSF_ROUTER_SESSION; a_router: WSF_ROUTER)
|
try (a_path: READABLE_STRING_8; req: WSF_REQUEST; res: WSF_RESPONSE; sess: WSF_ROUTER_SESSION; a_router: WSF_ROUTER)
|
||||||
-- <Precursor>
|
-- <Precursor>
|
||||||
local
|
local
|
||||||
p: READABLE_STRING_8
|
|
||||||
s: like based_uri
|
s: like based_uri
|
||||||
do
|
do
|
||||||
p := path_from_request (req)
|
|
||||||
s := based_uri (uri, a_router)
|
s := based_uri (uri, a_router)
|
||||||
if p.starts_with (s) then
|
if a_path.starts_with (s) then
|
||||||
sess.set_dispatched_handler (handler)
|
sess.set_dispatched_handler (handler)
|
||||||
a_router.execute_before (Current)
|
a_router.execute_before (Current)
|
||||||
execute_handler (handler, s, req, res)
|
execute_handler (handler, s, req, res)
|
||||||
@@ -113,7 +109,7 @@ invariant
|
|||||||
uri_attached: uri /= Void
|
uri_attached: uri /= Void
|
||||||
|
|
||||||
note
|
note
|
||||||
copyright: "2011-2013, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Eiffel Software and others"
|
copyright: "2011-2015, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Colin Adams, Eiffel Software and others"
|
||||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||||
source: "[
|
source: "[
|
||||||
Eiffel Software
|
Eiffel Software
|
||||||
|
|||||||
@@ -50,13 +50,13 @@ feature -- Documentation
|
|||||||
|
|
||||||
feature -- Status
|
feature -- Status
|
||||||
|
|
||||||
is_mapping (req: WSF_REQUEST; a_router: WSF_ROUTER): BOOLEAN
|
is_mapping (a_path: READABLE_STRING_8; req: WSF_REQUEST; a_router: WSF_ROUTER): BOOLEAN
|
||||||
-- <Precursor>
|
-- <Precursor>
|
||||||
local
|
local
|
||||||
p: READABLE_STRING_8
|
p: READABLE_STRING_8
|
||||||
l_uri: like uri
|
l_uri: like uri
|
||||||
do
|
do
|
||||||
p := path_from_request (req)
|
p := a_path
|
||||||
l_uri := based_uri (uri, a_router)
|
l_uri := based_uri (uri, a_router)
|
||||||
if l_uri.ends_with ("/") then
|
if l_uri.ends_with ("/") then
|
||||||
if not p.ends_with ("/") then
|
if not p.ends_with ("/") then
|
||||||
@@ -72,10 +72,10 @@ feature -- Status
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
try (req: WSF_REQUEST; res: WSF_RESPONSE; sess: WSF_ROUTER_SESSION; a_router: WSF_ROUTER)
|
try (a_path: READABLE_STRING_8; req: WSF_REQUEST; res: WSF_RESPONSE; sess: WSF_ROUTER_SESSION; a_router: WSF_ROUTER)
|
||||||
-- <Precursor>
|
-- <Precursor>
|
||||||
do
|
do
|
||||||
if is_mapping (req, a_router) then
|
if is_mapping (a_path, req, a_router) then
|
||||||
sess.set_dispatched_handler (handler)
|
sess.set_dispatched_handler (handler)
|
||||||
a_router.execute_before (Current)
|
a_router.execute_before (Current)
|
||||||
execute_handler (handler, req, res)
|
execute_handler (handler, req, res)
|
||||||
@@ -106,7 +106,7 @@ feature {NONE} -- Implementation
|
|||||||
end
|
end
|
||||||
|
|
||||||
note
|
note
|
||||||
copyright: "2011-2013, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Eiffel Software and others"
|
copyright: "2011-2015, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Colin Adams, Eiffel Software and others"
|
||||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||||
source: "[
|
source: "[
|
||||||
Eiffel Software
|
Eiffel Software
|
||||||
|
|||||||
@@ -57,27 +57,23 @@ feature -- Documentation
|
|||||||
|
|
||||||
feature -- Status
|
feature -- Status
|
||||||
|
|
||||||
is_mapping (req: WSF_REQUEST; a_router: WSF_ROUTER): BOOLEAN
|
is_mapping (a_path: READABLE_STRING_8; req: WSF_REQUEST; a_router: WSF_ROUTER): BOOLEAN
|
||||||
-- <Precursor>
|
-- <Precursor>
|
||||||
local
|
local
|
||||||
tpl: URI_TEMPLATE
|
tpl: URI_TEMPLATE
|
||||||
p: READABLE_STRING_8
|
|
||||||
do
|
do
|
||||||
p := path_from_request (req)
|
|
||||||
tpl := based_uri_template (template, a_router)
|
tpl := based_uri_template (template, a_router)
|
||||||
Result := tpl.match (p) /= Void
|
Result := tpl.match (a_path) /= Void
|
||||||
end
|
end
|
||||||
|
|
||||||
try (req: WSF_REQUEST; res: WSF_RESPONSE; sess: WSF_ROUTER_SESSION; a_router: WSF_ROUTER)
|
try (a_path: READABLE_STRING_8; req: WSF_REQUEST; res: WSF_RESPONSE; sess: WSF_ROUTER_SESSION; a_router: WSF_ROUTER)
|
||||||
-- <Precursor>
|
-- <Precursor>
|
||||||
local
|
local
|
||||||
tpl: URI_TEMPLATE
|
tpl: URI_TEMPLATE
|
||||||
p: READABLE_STRING_8
|
|
||||||
new_src: detachable WSF_REQUEST_PATH_PARAMETERS_PROVIDER
|
new_src: detachable WSF_REQUEST_PATH_PARAMETERS_PROVIDER
|
||||||
do
|
do
|
||||||
p := path_from_request (req)
|
|
||||||
tpl := based_uri_template (template, a_router)
|
tpl := based_uri_template (template, a_router)
|
||||||
if attached tpl.match (p) as tpl_res then
|
if attached tpl.match (a_path) as tpl_res then
|
||||||
sess.set_dispatched_handler (handler)
|
sess.set_dispatched_handler (handler)
|
||||||
a_router.execute_before (Current)
|
a_router.execute_before (Current)
|
||||||
--| Applied the context to the request
|
--| Applied the context to the request
|
||||||
@@ -126,7 +122,7 @@ feature {NONE} -- Implementation
|
|||||||
end
|
end
|
||||||
|
|
||||||
note
|
note
|
||||||
copyright: "2011-2013, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Eiffel Software and others"
|
copyright: "2011-2015, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Colin Adams, Eiffel Software and others"
|
||||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||||
source: "[
|
source: "[
|
||||||
Eiffel Software
|
Eiffel Software
|
||||||
|
|||||||
@@ -170,6 +170,20 @@ feature -- Basic operations
|
|||||||
Result := sess.dispatched_handler
|
Result := sess.dispatched_handler
|
||||||
end
|
end
|
||||||
|
|
||||||
|
feature {WSF_ROUTER_MAPPING} -- Dispatch helper
|
||||||
|
|
||||||
|
path_to_dispatch (req: WSF_REQUEST): READABLE_STRING_8
|
||||||
|
-- Path used by the router, to apply url dispatching of request `req'.
|
||||||
|
-- This can be redefined in descendant, to apply various url mapping, or aliasing
|
||||||
|
-- if needed, or for other purpose.
|
||||||
|
require
|
||||||
|
req_attached: req /= Void
|
||||||
|
do
|
||||||
|
Result := req.percent_encoded_path_info
|
||||||
|
ensure
|
||||||
|
path_from_request_attached: Result /= Void
|
||||||
|
end
|
||||||
|
|
||||||
feature {NONE} -- Dispatch implementation
|
feature {NONE} -- Dispatch implementation
|
||||||
|
|
||||||
router_dispatch (req: WSF_REQUEST; res: WSF_RESPONSE; sess: WSF_ROUTER_SESSION)
|
router_dispatch (req: WSF_REQUEST; res: WSF_RESPONSE; sess: WSF_ROUTER_SESSION)
|
||||||
@@ -203,7 +217,9 @@ feature {NONE} -- Dispatch implementation
|
|||||||
a_request_method_attached: a_request_method /= Void
|
a_request_method_attached: a_request_method /= Void
|
||||||
local
|
local
|
||||||
m: WSF_ROUTER_MAPPING
|
m: WSF_ROUTER_MAPPING
|
||||||
|
p: like path_to_dispatch
|
||||||
do
|
do
|
||||||
|
p := path_to_dispatch (req)
|
||||||
across
|
across
|
||||||
mappings as c
|
mappings as c
|
||||||
until
|
until
|
||||||
@@ -212,7 +228,7 @@ feature {NONE} -- Dispatch implementation
|
|||||||
if attached c.item as l_info then
|
if attached c.item as l_info then
|
||||||
if is_matching_request_methods (a_request_method, l_info.request_methods) then
|
if is_matching_request_methods (a_request_method, l_info.request_methods) then
|
||||||
m := l_info.mapping
|
m := l_info.mapping
|
||||||
m.try (req, res, sess, Current)
|
m.try (p, req, res, sess, Current)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -320,16 +336,17 @@ feature -- Status report
|
|||||||
local
|
local
|
||||||
m: WSF_ROUTER_MAPPING
|
m: WSF_ROUTER_MAPPING
|
||||||
l_rqsmethods: detachable WSF_REQUEST_METHODS
|
l_rqsmethods: detachable WSF_REQUEST_METHODS
|
||||||
|
p: like path_to_dispatch
|
||||||
do
|
do
|
||||||
create Result
|
create Result
|
||||||
|
p := path_to_dispatch (req)
|
||||||
across
|
across
|
||||||
mappings as c
|
mappings as c
|
||||||
loop
|
loop
|
||||||
m := c.item.mapping
|
m := c.item.mapping
|
||||||
if attached {WSF_ROUTING_HANDLER} m.handler as l_routing then
|
if attached {WSF_ROUTING_HANDLER} m.handler as l_routing then
|
||||||
l_rqsmethods := l_routing.router.allowed_methods_for_request (req)
|
l_rqsmethods := l_routing.router.allowed_methods_for_request (req)
|
||||||
elseif m.is_mapping (req, Current) then
|
elseif m.is_mapping (p, req, Current) then
|
||||||
l_rqsmethods := c.item.request_methods
|
l_rqsmethods := c.item.request_methods
|
||||||
else
|
else
|
||||||
l_rqsmethods := Void
|
l_rqsmethods := Void
|
||||||
@@ -576,7 +593,7 @@ invariant
|
|||||||
pre_execution_actions_attached: pre_execution_actions /= Void
|
pre_execution_actions_attached: pre_execution_actions /= Void
|
||||||
|
|
||||||
note
|
note
|
||||||
copyright: "2011-2014, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Colin Adams, Eiffel Software and others"
|
copyright: "2011-2015, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Colin Adams, Eiffel Software and others"
|
||||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||||
source: "[
|
source: "[
|
||||||
Eiffel Software
|
Eiffel Software
|
||||||
|
|||||||
@@ -56,18 +56,20 @@ feature -- Status report
|
|||||||
|
|
||||||
feature -- Status
|
feature -- Status
|
||||||
|
|
||||||
is_mapping (req: WSF_REQUEST; a_router: WSF_ROUTER): BOOLEAN
|
is_mapping (a_path: READABLE_STRING_8; req: WSF_REQUEST; a_router: WSF_ROUTER): BOOLEAN
|
||||||
-- Does `Current' accept `req' when using `a_router'?
|
-- Does `Current' accept path `a_path' and request `req' when using `a_router'?
|
||||||
require
|
require
|
||||||
|
a_path_attached: a_path /= Void
|
||||||
req_attached: req /= Void
|
req_attached: req /= Void
|
||||||
a_router_attached: a_router /= Void
|
a_router_attached: a_router /= Void
|
||||||
deferred
|
deferred
|
||||||
end
|
end
|
||||||
|
|
||||||
try (req: WSF_REQUEST; res: WSF_RESPONSE; sess: WSF_ROUTER_SESSION; a_router: WSF_ROUTER)
|
try (a_path: READABLE_STRING_8; req: WSF_REQUEST; res: WSF_RESPONSE; sess: WSF_ROUTER_SESSION; a_router: WSF_ROUTER)
|
||||||
-- Try using `Current' mapping and if it matches request `req'
|
-- Try using `Current' mapping and if it matches path `a_path' and request `req'
|
||||||
-- execute associated handler and set this handler in session `sess'.
|
-- execute associated handler and set this handler in session `sess'.
|
||||||
require
|
require
|
||||||
|
a_path_attached: a_path /= Void
|
||||||
req_attached: req /= Void
|
req_attached: req /= Void
|
||||||
res_attached: res /= Void
|
res_attached: res /= Void
|
||||||
sess_attached: sess /= Void
|
sess_attached: sess /= Void
|
||||||
@@ -75,20 +77,8 @@ feature -- Status
|
|||||||
deferred
|
deferred
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Helper
|
|
||||||
|
|
||||||
path_from_request (req: WSF_REQUEST): READABLE_STRING_8
|
|
||||||
-- Path used by `Current' to check that mapping matches request `req'
|
|
||||||
require
|
|
||||||
req_attached: req /= Void
|
|
||||||
do
|
|
||||||
Result := req.percent_encoded_path_info
|
|
||||||
ensure
|
|
||||||
path_from_request_attached: Result /= Void
|
|
||||||
end
|
|
||||||
|
|
||||||
note
|
note
|
||||||
copyright: "2011-2014, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Colin Adams, Eiffel Software and others"
|
copyright: "2011-2015, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Colin Adams, Eiffel Software and others"
|
||||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||||
source: "[
|
source: "[
|
||||||
Eiffel Software
|
Eiffel Software
|
||||||
|
|||||||
Reference in New Issue
Block a user