Removed default handler for WSF_ROUTER
Added WSF_ROUTE to replace a TUPLE [H, C] WSF_ROUTER.route (req): detachable WSF_ROUTE WSF_ROUTER.execute_route (a_route, req, res) To help usage of Routers Remove WSF_HANDLER_CONTEXT obsolete features. Added comments
This commit is contained in:
@@ -1,6 +1,25 @@
|
||||
note
|
||||
description: "Summary description for {WSF_ROUTING_HANDLER }."
|
||||
author: ""
|
||||
description: "[
|
||||
WSF_ROUTING_HANDLER is mainly to group a set of handler having the same base
|
||||
such as /users for
|
||||
/users/by/id/{id}
|
||||
/users/by/name/name}
|
||||
|
||||
It can be used to optimize the router, where the router checks only the base path before checking each entries
|
||||
Then for
|
||||
/a/a1
|
||||
/a/a2
|
||||
/a/a3
|
||||
/a/a4
|
||||
/b/b1
|
||||
/b/b2
|
||||
/b/b3
|
||||
2 routing handlers could be used "/a" and "/b"
|
||||
then to find the /b/b2 match, the router has to do only
|
||||
/a /b /b/b1 and /b/b2 i.e: 4 checks
|
||||
instead of /a/a1 /a/a2 /a/a3 /a/a4 /b/b1 /b/b2: i.e: 6 checks
|
||||
On router with deep arborescence this could be significant
|
||||
]"
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
@@ -40,11 +59,13 @@ feature -- Execution
|
||||
execute (ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
-- Execute request handler
|
||||
local
|
||||
hdl: detachable H
|
||||
r: detachable WSF_ROUTE [H, C]
|
||||
do
|
||||
hdl := router.dispatch_and_return_handler (req, res)
|
||||
if hdl = Void then
|
||||
r := router.route (req)
|
||||
if r = Void then
|
||||
res.put_header ({HTTP_STATUS_CODE}.not_found, <<[{HTTP_HEADER_NAMES}.header_content_length, "0"]>>)
|
||||
else
|
||||
router.execute_route (r, req, res)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -56,14 +77,6 @@ feature {NONE} -- Routing
|
||||
|
||||
feature -- Mapping
|
||||
|
||||
map_default (h: detachable H)
|
||||
-- Map default handler
|
||||
-- If no route/handler is found,
|
||||
-- then use `default_handler' as default if not Void
|
||||
do
|
||||
router.map_default (h)
|
||||
end
|
||||
|
||||
map (a_resource: READABLE_STRING_8; h: H)
|
||||
-- Map handler `h' with `a_resource'
|
||||
do
|
||||
|
||||
Reference in New Issue
Block a user