changing design to use generic instead of anchor types

This commit is contained in:
Jocelyn Fiat
2011-09-09 16:24:11 +02:00
parent 11286eeeef
commit 32197d0513
12 changed files with 236 additions and 69 deletions

View File

@@ -10,7 +10,7 @@ class
inherit inherit
ANY ANY
ROUTED_APPLICATION DEFAULT_URI_TEMPLATE_ROUTED_APPLICATION
ROUTED_APPLICATION_HELPER ROUTED_APPLICATION_HELPER
@@ -29,18 +29,12 @@ feature {NONE} -- Initialization
create_router create_router
do do
debug create router.make (5)
create {REQUEST_URI_ROUTER} router.make (5)
create {REQUEST_URI_TEMPLATE_ROUTER} router.make (5)
end
-- create {REQUEST_URI_ROUTER} router.make (5)
create {REQUEST_URI_TEMPLATE_ROUTER} router.make (5)
end end
setup_router setup_router
local local
ra: REQUEST_AGENT_HANDLER ra: REQUEST_AGENT_HANDLER [REQUEST_URI_TEMPLATE_HANDLER_CONTEXT]
do do
router.map_agent ("/home", agent execute_home) router.map_agent ("/home", agent execute_home)
@@ -107,7 +101,7 @@ feature -- Execution
res.flush res.flush
end end
execute_home (ctx: REQUEST_HANDLER_CONTEXT; req: WGI_REQUEST; res: WGI_RESPONSE_BUFFER) execute_home (ctx: REQUEST_URI_TEMPLATE_HANDLER_CONTEXT; req: WGI_REQUEST; res: WGI_RESPONSE_BUFFER)
do do
res.write_header (200, <<["Content-Type", "text/html"]>>) res.write_header (200, <<["Content-Type", "text/html"]>>)
res.write_string ("<html><body>Hello World ?!%N") res.write_string ("<html><body>Hello World ?!%N")
@@ -171,33 +165,33 @@ feature -- Execution
end end
end end
handle_hello (ctx: REQUEST_HANDLER_CONTEXT; req: WGI_REQUEST; res: WGI_RESPONSE_BUFFER) handle_hello (ctx: REQUEST_URI_TEMPLATE_HANDLER_CONTEXT; req: WGI_REQUEST; res: WGI_RESPONSE_BUFFER)
do do
execute_hello (req, res, Void, ctx) execute_hello (req, res, Void, ctx)
end end
handle_anonymous_hello (ctx: REQUEST_HANDLER_CONTEXT; req: WGI_REQUEST; res: WGI_RESPONSE_BUFFER) handle_anonymous_hello (ctx: REQUEST_URI_TEMPLATE_HANDLER_CONTEXT; req: WGI_REQUEST; res: WGI_RESPONSE_BUFFER)
do do
execute_hello (req, res, ctx.parameter ("name"), ctx) execute_hello (req, res, ctx.parameter ("name"), ctx)
end end
handle_method_any (ctx: REQUEST_HANDLER_CONTEXT; req: WGI_REQUEST; res: WGI_RESPONSE_BUFFER) handle_method_any (ctx: REQUEST_URI_TEMPLATE_HANDLER_CONTEXT; req: WGI_REQUEST; res: WGI_RESPONSE_BUFFER)
do do
execute_hello (req, res, req.request_method, ctx) execute_hello (req, res, req.request_method, ctx)
end end
handle_method_get (ctx: REQUEST_HANDLER_CONTEXT; req: WGI_REQUEST; res: WGI_RESPONSE_BUFFER) handle_method_get (ctx: REQUEST_URI_TEMPLATE_HANDLER_CONTEXT; req: WGI_REQUEST; res: WGI_RESPONSE_BUFFER)
do do
execute_hello (req, res, "GET", ctx) execute_hello (req, res, "GET", ctx)
end end
handle_method_post (ctx: REQUEST_HANDLER_CONTEXT; req: WGI_REQUEST; res: WGI_RESPONSE_BUFFER) handle_method_post (ctx: REQUEST_URI_TEMPLATE_HANDLER_CONTEXT; req: WGI_REQUEST; res: WGI_RESPONSE_BUFFER)
do do
execute_hello (req, res, "POST", ctx) execute_hello (req, res, "POST", ctx)
end end
handle_method_get_or_post (ctx: REQUEST_HANDLER_CONTEXT; req: WGI_REQUEST; res: WGI_RESPONSE_BUFFER) handle_method_get_or_post (ctx: REQUEST_URI_TEMPLATE_HANDLER_CONTEXT; req: WGI_REQUEST; res: WGI_RESPONSE_BUFFER)
do do
execute_hello (req, res, "GET or POST", ctx) execute_hello (req, res, "GET or POST", ctx)
end end

View File

@@ -5,7 +5,7 @@ note
revision: "$Revision$" revision: "$Revision$"
deferred class deferred class
ROUTED_APPLICATION ROUTED_APPLICATION [H -> REQUEST_HANDLER [C], C -> REQUEST_HANDLER_CONTEXT]
feature -- Setup feature -- Setup
@@ -30,7 +30,7 @@ feature -- Setup
deferred deferred
end end
router: REQUEST_ROUTER router: REQUEST_ROUTER [H, C]
-- Request router -- Request router
feature -- Execution feature -- Execution

View File

@@ -0,0 +1,39 @@
note
description: "Summary description for {DEFAULT_REQUEST_URI_ROUTER}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
DEFAULT_REQUEST_URI_ROUTER
inherit
REQUEST_URI_ROUTER [REQUEST_HANDLER [REQUEST_URI_HANDLER_CONTEXT], REQUEST_URI_HANDLER_CONTEXT]
redefine
map_agent_with_request_methods
end
create
make
feature -- Mapping
map_agent_with_request_methods (a_id: READABLE_STRING_8; a_action: PROCEDURE [ANY, TUPLE [ctx: REQUEST_URI_HANDLER_CONTEXT; req: WGI_REQUEST; res: WGI_RESPONSE_BUFFER]];
rqst_methods: detachable ARRAY [READABLE_STRING_8])
local
h: REQUEST_AGENT_HANDLER [REQUEST_URI_HANDLER_CONTEXT]
do
create h.make (a_action)
map_with_request_methods (a_id, h, rqst_methods)
end
note
copyright: "2011-2011, 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

View File

@@ -0,0 +1,40 @@
note
description: "Summary description for {DEFAULT_REQUEST_URI_TEMPLATE_ROUTER}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
DEFAULT_REQUEST_URI_TEMPLATE_ROUTER
inherit
REQUEST_URI_TEMPLATE_ROUTER [REQUEST_HANDLER [REQUEST_URI_TEMPLATE_HANDLER_CONTEXT], REQUEST_URI_TEMPLATE_HANDLER_CONTEXT]
redefine
map_agent_with_request_methods
end
create
make
feature -- Mapping
map_agent_with_request_methods (a_id: READABLE_STRING_8; a_action: PROCEDURE [ANY, TUPLE [ctx: REQUEST_URI_TEMPLATE_HANDLER_CONTEXT; req: WGI_REQUEST; res: WGI_RESPONSE_BUFFER]];
rqst_methods: detachable ARRAY [READABLE_STRING_8])
local
h: REQUEST_AGENT_HANDLER [REQUEST_URI_TEMPLATE_HANDLER_CONTEXT]
do
create h.make (a_action)
map_with_request_methods (a_id, h, rqst_methods)
end
note
copyright: "2011-2011, 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

View File

@@ -0,0 +1,23 @@
note
description: "Summary description for {DEFAULT_ROUTED_APPLICATION}."
author: ""
date: "$Date$"
revision: "$Revision$"
deferred class
DEFAULT_ROUTED_APPLICATION
inherit
ROUTED_APPLICATION [REQUEST_HANDLER [REQUEST_HANDLER_CONTEXT], REQUEST_HANDLER_CONTEXT]
note
copyright: "2011-2011, 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

View File

@@ -0,0 +1,30 @@
note
description: "Summary description for {DEFAULT_URI_ROUTED_APPLICATION}."
author: ""
date: "$Date$"
revision: "$Revision$"
deferred class
DEFAULT_URI_ROUTED_APPLICATION
inherit
ROUTED_APPLICATION [REQUEST_HANDLER [REQUEST_URI_HANDLER_CONTEXT], REQUEST_URI_HANDLER_CONTEXT]
redefine
router
end
feature -- Router
router: DEFAULT_REQUEST_URI_ROUTER
;note
copyright: "2011-2011, 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

View File

@@ -0,0 +1,30 @@
note
description: "Summary description for {DEFAULT_URI_TEMPLATE_ROUTED_APPLICATION}."
author: ""
date: "$Date$"
revision: "$Revision$"
deferred class
DEFAULT_URI_TEMPLATE_ROUTED_APPLICATION
inherit
ROUTED_APPLICATION [REQUEST_HANDLER [REQUEST_URI_TEMPLATE_HANDLER_CONTEXT], REQUEST_URI_TEMPLATE_HANDLER_CONTEXT]
redefine
router
end
feature -- Router
router: DEFAULT_REQUEST_URI_TEMPLATE_ROUTER
;note
copyright: "2011-2011, 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

View File

@@ -5,10 +5,10 @@ note
revision: "$Revision$" revision: "$Revision$"
class class
REQUEST_AGENT_HANDLER REQUEST_AGENT_HANDLER [C -> REQUEST_HANDLER_CONTEXT]
inherit inherit
REQUEST_HANDLER REQUEST_HANDLER [C]
create create
make make
@@ -23,11 +23,11 @@ feature -- Initialization
feature -- Access feature -- Access
action: PROCEDURE [ANY, TUPLE [ctx: REQUEST_HANDLER_CONTEXT; req: WGI_REQUEST; res: WGI_RESPONSE_BUFFER]] action: PROCEDURE [ANY, TUPLE [ctx: C; req: WGI_REQUEST; res: WGI_RESPONSE_BUFFER]]
feature -- Execution feature -- Execution
execute_application (ctx: REQUEST_HANDLER_CONTEXT; req: WGI_REQUEST; res: WGI_RESPONSE_BUFFER) execute_application (ctx: C; req: WGI_REQUEST; res: WGI_RESPONSE_BUFFER)
do do
action.call ([ctx, req, res]) action.call ([ctx, req, res])
end end

View File

@@ -5,7 +5,7 @@ note
revision: "$Revision$" revision: "$Revision$"
deferred class deferred class
REQUEST_HANDLER REQUEST_HANDLER [C -> REQUEST_HANDLER_CONTEXT]
inherit inherit
ANY ANY
@@ -37,7 +37,7 @@ feature -- Status report
feature -- Execution feature -- Execution
execute (a_hdl_context: REQUEST_HANDLER_CONTEXT; req: WGI_REQUEST; res: WGI_RESPONSE_BUFFER) execute (a_hdl_context: C; req: WGI_REQUEST; res: WGI_RESPONSE_BUFFER)
-- Execute request handler -- Execute request handler
require require
is_valid_context: is_valid_context (req) is_valid_context: is_valid_context (req)
@@ -60,7 +60,7 @@ feature -- Execution
retry retry
end end
execute_application (a_hdl_context: REQUEST_HANDLER_CONTEXT; req: WGI_REQUEST; res: WGI_RESPONSE_BUFFER) execute_application (a_hdl_context: C; req: WGI_REQUEST; res: WGI_RESPONSE_BUFFER)
-- Execute request handler -- Execute request handler
deferred deferred
end end

View File

@@ -5,9 +5,9 @@ note
revision: "$Revision$" revision: "$Revision$"
deferred class deferred class
REQUEST_ROUTER REQUEST_ROUTER [H -> REQUEST_HANDLER [C], C -> REQUEST_HANDLER_CONTEXT]
feature -- Registration feature -- Mapping
map_default (r: like default_handler) map_default (r: like default_handler)
-- Map default handler -- Map default handler
@@ -17,28 +17,33 @@ feature -- Registration
set_default_handler (r) set_default_handler (r)
end end
map (a_id: READABLE_STRING_8; h: REQUEST_HANDLER) map (a_id: READABLE_STRING_8; h: H)
-- Map handler `h' with `a_id' -- Map handler `h' with `a_id'
do do
map_with_request_methods (a_id, h, Void) map_with_request_methods (a_id, h, Void)
end end
map_with_request_methods (a_id: READABLE_STRING_8; h: REQUEST_HANDLER; rqst_methods: detachable ARRAY [READABLE_STRING_8]) map_with_request_methods (a_id: READABLE_STRING_8; h: H; rqst_methods: detachable ARRAY [READABLE_STRING_8])
-- Map handler `h' with `a_id' and `rqst_methods' -- Map handler `h' with `a_id' and `rqst_methods'
deferred deferred
end end
map_agent (a_id: READABLE_STRING_8; a_action: like {REQUEST_AGENT_HANDLER}.action) map_agent (a_id: READABLE_STRING_8; a_action: PROCEDURE [ANY, TUPLE [ctx: C; req: WGI_REQUEST; res: WGI_RESPONSE_BUFFER]])
do do
map_agent_with_request_methods (a_id, a_action, Void) map_agent_with_request_methods (a_id, a_action, Void)
end end
map_agent_with_request_methods (a_id: READABLE_STRING_8; a_action: like {REQUEST_AGENT_HANDLER}.action; rqst_methods: detachable ARRAY [READABLE_STRING_8]) map_agent_with_request_methods (a_id: READABLE_STRING_8; a_action: PROCEDURE [ANY, TUPLE [ctx: C; req: WGI_REQUEST; res: WGI_RESPONSE_BUFFER]];
rqst_methods: detachable ARRAY [READABLE_STRING_8])
local local
h: REQUEST_AGENT_HANDLER rah: REQUEST_AGENT_HANDLER [C]
do do
create h.make (a_action) create rah.make (a_action)
if attached {H} rah as h then
map_with_request_methods (a_id, h, rqst_methods) map_with_request_methods (a_id, h, rqst_methods)
else
check valid_agent_handler: False end
end
end end
feature -- Execution feature -- Execution
@@ -50,7 +55,7 @@ feature -- Execution
Result := dispatch_and_return_handler (req, res) /= Void Result := dispatch_and_return_handler (req, res) /= Void
end end
dispatch_and_return_handler (req: WGI_REQUEST; res: WGI_RESPONSE_BUFFER): like default_handler dispatch_and_return_handler (req: WGI_REQUEST; res: WGI_RESPONSE_BUFFER): detachable H
-- Dispatch `req, res' to the associated handler -- Dispatch `req, res' to the associated handler
-- And return this handler -- And return this handler
-- If Result is Void, this means no handler was found. -- If Result is Void, this means no handler was found.
@@ -77,7 +82,7 @@ feature -- Execution
feature -- Traversing feature -- Traversing
new_cursor: ITERATION_CURSOR [TUPLE [handler: REQUEST_HANDLER; resource: READABLE_STRING_8; request_methods: detachable ARRAY [READABLE_STRING_8]]] new_cursor: ITERATION_CURSOR [TUPLE [handler: H; resource: READABLE_STRING_8; request_methods: detachable ARRAY [READABLE_STRING_8]]]
-- Fresh cursor associated with current structure -- Fresh cursor associated with current structure
deferred deferred
ensure ensure
@@ -86,7 +91,7 @@ feature -- Traversing
feature {NONE} -- Access: Implementation feature {NONE} -- Access: Implementation
handler (req: WGI_REQUEST): detachable TUPLE [handler: attached like default_handler; context: like default_handler_context] handler (req: WGI_REQUEST): detachable TUPLE [handler: H; context: like default_handler_context]
-- Handler whose map matched with `req' -- Handler whose map matched with `req'
require require
req_valid: req /= Void and then req.path_info /= Void req_valid: req /= Void and then req.path_info /= Void
@@ -146,12 +151,12 @@ feature {NONE} -- Implementation
default_handler_set: h = default_handler default_handler_set: h = default_handler
end end
default_handler: detachable REQUEST_HANDLER default_handler: detachable H
-- Default handler -- Default handler
deferred deferred
end end
default_handler_context (req: WGI_REQUEST): REQUEST_HANDLER_CONTEXT default_handler_context (req: WGI_REQUEST): C
-- Default handler context associated with `default_handler' -- Default handler context associated with `default_handler'
require require
has_default_handler: default_handler /= Void has_default_handler: default_handler /= Void

View File

@@ -5,10 +5,10 @@ note
revision: "$Revision$" revision: "$Revision$"
class class
REQUEST_URI_ROUTER REQUEST_URI_ROUTER [H -> REQUEST_HANDLER [C], C -> REQUEST_URI_HANDLER_CONTEXT create make end]
inherit inherit
REQUEST_ROUTER REQUEST_ROUTER [H, C]
create create
make make
@@ -23,16 +23,16 @@ feature -- Initialization
feature -- Registration feature -- Registration
map_with_request_methods (p: READABLE_STRING_8; h: REQUEST_HANDLER; rqst_methods: detachable ARRAY [READABLE_STRING_8]) map_with_request_methods (p: READABLE_STRING_8; h: H; rqst_methods: detachable ARRAY [READABLE_STRING_8])
do do
handlers.force ([h, p, formatted_request_methods (rqst_methods)]) handlers.force ([h, p, formatted_request_methods (rqst_methods)])
end end
feature {NONE} -- Access: Implementation feature {NONE} -- Access: Implementation
handler (req: WGI_REQUEST): detachable TUPLE [handler: REQUEST_HANDLER; context: like default_handler_context] handler (req: WGI_REQUEST): detachable TUPLE [handler: H; context: like default_handler_context]
local local
h: detachable REQUEST_HANDLER h: detachable H
ctx: detachable like default_handler_context ctx: detachable like default_handler_context
do do
h := handler_by_path (req.path_info, req.request_method) h := handler_by_path (req.path_info, req.request_method)
@@ -54,7 +54,7 @@ feature {NONE} -- Access: Implementation
end end
end end
smart_handler (req: WGI_REQUEST): detachable TUPLE [path: READABLE_STRING_8; handler: REQUEST_HANDLER] smart_handler (req: WGI_REQUEST): detachable TUPLE [path: READABLE_STRING_8; handler: H]
require require
req_valid: req /= Void and then req.path_info /= Void req_valid: req /= Void and then req.path_info /= Void
do do
@@ -63,7 +63,7 @@ feature {NONE} -- Access: Implementation
req_path_info_unchanged: req.path_info.same_string (old req.path_info) req_path_info_unchanged: req.path_info.same_string (old req.path_info)
end end
handler_by_path (a_path: READABLE_STRING_GENERAL; rqst_method: READABLE_STRING_GENERAL): detachable REQUEST_HANDLER handler_by_path (a_path: READABLE_STRING_GENERAL; rqst_method: READABLE_STRING_GENERAL): detachable H
require require
a_path_valid: a_path /= Void a_path_valid: a_path /= Void
local local
@@ -86,13 +86,13 @@ feature {NONE} -- Access: Implementation
a_path_unchanged: a_path.same_string (old a_path) a_path_unchanged: a_path.same_string (old a_path)
end end
smart_handler_by_path (a_path: READABLE_STRING_8; rqst_method: READABLE_STRING_GENERAL): detachable TUPLE [path: READABLE_STRING_8; handler: REQUEST_HANDLER] smart_handler_by_path (a_path: READABLE_STRING_8; rqst_method: READABLE_STRING_GENERAL): detachable TUPLE [path: READABLE_STRING_8; handler: H]
require require
a_path_valid: a_path /= Void a_path_valid: a_path /= Void
local local
p: INTEGER p: INTEGER
l_context_path, l_path: READABLE_STRING_8 l_context_path, l_path: READABLE_STRING_8
h: detachable REQUEST_HANDLER h: detachable H
do do
l_context_path := context_path (a_path) l_context_path := context_path (a_path)
from from
@@ -116,18 +116,21 @@ feature {NONE} -- Access: Implementation
feature {NONE} -- Context factory feature {NONE} -- Context factory
handler_context (p: detachable STRING; req: WGI_REQUEST): like default_handler_context handler_context (p: detachable STRING; req: WGI_REQUEST): C
local
ctx: C
do do
if p /= Void then if p /= Void then
create {REQUEST_URI_HANDLER_CONTEXT} Result.make (req, p) create ctx.make (req, p)
else else
create {REQUEST_URI_HANDLER_CONTEXT} Result.make (req, req.path_info) create ctx.make (req, req.path_info)
end end
Result := ctx
end end
feature -- Access feature -- Access
new_cursor: ITERATION_CURSOR [TUPLE [handler: REQUEST_HANDLER; resource: READABLE_STRING_8; request_methods: detachable ARRAY [READABLE_STRING_8]]] new_cursor: ITERATION_CURSOR [TUPLE [handler: H; resource: READABLE_STRING_8; request_methods: detachable ARRAY [READABLE_STRING_8]]]
-- Fresh cursor associated with current structure -- Fresh cursor associated with current structure
do do
Result := handlers.new_cursor Result := handlers.new_cursor
@@ -135,7 +138,7 @@ feature -- Access
feature {NONE} -- Implementation feature {NONE} -- Implementation
handlers: ARRAYED_LIST [TUPLE [handler: REQUEST_HANDLER; resource: READABLE_STRING_8; request_methods: detachable ARRAY [READABLE_STRING_8]]] handlers: ARRAYED_LIST [TUPLE [handler: H; resource: READABLE_STRING_8; request_methods: detachable ARRAY [READABLE_STRING_8]]]
-- Handlers indexed by the template expression -- Handlers indexed by the template expression
-- see `templates' -- see `templates'
@@ -166,14 +169,14 @@ feature {NONE} -- Implementation
feature {NONE} -- Default: implementation feature {NONE} -- Default: implementation
default_handler: detachable REQUEST_HANDLER default_handler: detachable H
set_default_handler (h: like default_handler) set_default_handler (h: like default_handler)
do do
default_handler := h default_handler := h
end end
default_handler_context (req: WGI_REQUEST): REQUEST_HANDLER_CONTEXT default_handler_context (req: WGI_REQUEST): C
do do
Result := handler_context (Void, req) Result := handler_context (Void, req)
end end

View File

@@ -5,10 +5,10 @@ note
revision: "$Revision$" revision: "$Revision$"
class class
REQUEST_URI_TEMPLATE_ROUTER REQUEST_URI_TEMPLATE_ROUTER [H -> REQUEST_HANDLER [C], C -> REQUEST_URI_TEMPLATE_HANDLER_CONTEXT create make end]
inherit inherit
REQUEST_ROUTER REQUEST_ROUTER [H, C]
create create
make make
@@ -24,18 +24,18 @@ feature -- Initialization
feature -- Registration feature -- Registration
map_with_uri_template (uri: URI_TEMPLATE; h: REQUEST_HANDLER) map_with_uri_template (uri: URI_TEMPLATE; h: H)
do do
map_with_uri_template_and_request_methods (uri, h, Void) map_with_uri_template_and_request_methods (uri, h, Void)
end end
map_with_uri_template_and_request_methods (uri: URI_TEMPLATE; h: REQUEST_HANDLER; rqst_methods: detachable ARRAY [READABLE_STRING_8]) map_with_uri_template_and_request_methods (uri: URI_TEMPLATE; h: H; rqst_methods: detachable ARRAY [READABLE_STRING_8])
do do
handlers.force ([h, uri.template, formatted_request_methods (rqst_methods)]) handlers.force ([h, uri.template, formatted_request_methods (rqst_methods)])
templates.force (uri, uri.template) templates.force (uri, uri.template)
end end
map_with_request_methods (tpl: READABLE_STRING_8; h: REQUEST_HANDLER; rqst_methods: detachable ARRAY [READABLE_STRING_8]) map_with_request_methods (tpl: READABLE_STRING_8; h: H; rqst_methods: detachable ARRAY [READABLE_STRING_8])
local local
uri: URI_TEMPLATE uri: URI_TEMPLATE
do do
@@ -76,18 +76,18 @@ feature {NONE} -- Access: Implementation
feature {NONE} -- Context factory feature {NONE} -- Context factory
handler_context (p: detachable STRING; req: WGI_REQUEST; tpl: URI_TEMPLATE; tpl_res: URI_TEMPLATE_MATCH_RESULT): like default_handler_context handler_context (p: detachable STRING; req: WGI_REQUEST; tpl: URI_TEMPLATE; tpl_res: URI_TEMPLATE_MATCH_RESULT): C
do do
if p /= Void then if p /= Void then
create {REQUEST_URI_TEMPLATE_HANDLER_CONTEXT} Result.make (req, tpl, tpl_res, p) create Result.make (req, tpl, tpl_res, p)
else else
create {REQUEST_URI_TEMPLATE_HANDLER_CONTEXT} Result.make (req, tpl, tpl_res, req.path_info) create Result.make (req, tpl, tpl_res, req.path_info)
end end
end end
feature -- Access: ITERABLE feature -- Access: ITERABLE
new_cursor: ITERATION_CURSOR [TUPLE [handler: REQUEST_HANDLER; resource: READABLE_STRING_8; request_methods: detachable ARRAY [READABLE_STRING_8]]] new_cursor: ITERATION_CURSOR [TUPLE [handler: H; resource: READABLE_STRING_8; request_methods: detachable ARRAY [READABLE_STRING_8]]]
-- Fresh cursor associated with current structure -- Fresh cursor associated with current structure
do do
Result := handlers.new_cursor Result := handlers.new_cursor
@@ -95,7 +95,7 @@ feature -- Access: ITERABLE
feature {NONE} -- Implementation feature {NONE} -- Implementation
handlers: ARRAYED_LIST [TUPLE [handler: REQUEST_HANDLER; resource: READABLE_STRING_8; request_methods: detachable ARRAY [READABLE_STRING_8]]] handlers: ARRAYED_LIST [TUPLE [handler: H; resource: READABLE_STRING_8; request_methods: detachable ARRAY [READABLE_STRING_8]]]
-- Handlers indexed by the template expression -- Handlers indexed by the template expression
-- see `templates' -- see `templates'
@@ -126,16 +126,19 @@ feature {NONE} -- Implementation
feature {NONE} -- Default: implementation feature {NONE} -- Default: implementation
default_handler: detachable REQUEST_HANDLER default_handler: detachable H
set_default_handler (h: like default_handler) set_default_handler (h: like default_handler)
do do
default_handler := h default_handler := h
end end
default_handler_context (req: WGI_REQUEST): REQUEST_HANDLER_CONTEXT default_handler_context (req: WGI_REQUEST): C
local
tpl: URI_TEMPLATE
do do
create {REQUEST_URI_HANDLER_CONTEXT} Result.make (req, "/") create tpl.make ("/")
Result := handler_context ("/", req, tpl, create {URI_TEMPLATE_MATCH_RESULT}.make_empty)
end end
;note ;note