adding routing handler
few renaming
This commit is contained in:
@@ -15,11 +15,6 @@ inherit
|
|||||||
{NONE} all
|
{NONE} all
|
||||||
end
|
end
|
||||||
|
|
||||||
HTTP_FORMAT_CONSTANTS
|
|
||||||
export
|
|
||||||
{NONE} all
|
|
||||||
end
|
|
||||||
|
|
||||||
feature -- Access
|
feature -- Access
|
||||||
|
|
||||||
request: WGI_REQUEST
|
request: WGI_REQUEST
|
||||||
@@ -28,9 +23,17 @@ feature -- Access
|
|||||||
path: READABLE_STRING_8
|
path: READABLE_STRING_8
|
||||||
-- Associated path
|
-- Associated path
|
||||||
|
|
||||||
request_format (a_format_variable_name: detachable STRING; content_type_supported: detachable ARRAY [STRING]): detachable READABLE_STRING_8
|
feature {NONE} -- Constants
|
||||||
|
|
||||||
|
Format_constants: HTTP_FORMAT_CONSTANTS
|
||||||
|
once
|
||||||
|
create Result
|
||||||
|
end
|
||||||
|
|
||||||
|
feature -- Query
|
||||||
|
|
||||||
|
request_format (a_format_variable_name: detachable READABLE_STRING_GENERAL; content_type_supported: detachable ARRAY [READABLE_STRING_8]): detachable READABLE_STRING_8
|
||||||
-- Format id for the request based on {HTTP_FORMAT_CONSTANTS}
|
-- Format id for the request based on {HTTP_FORMAT_CONSTANTS}
|
||||||
local
|
|
||||||
do
|
do
|
||||||
if a_format_variable_name /= Void and then attached parameter (a_format_variable_name) as ctx_format then
|
if a_format_variable_name /= Void and then attached parameter (a_format_variable_name) as ctx_format then
|
||||||
Result := ctx_format.as_string_8
|
Result := ctx_format.as_string_8
|
||||||
@@ -38,13 +41,12 @@ feature -- Access
|
|||||||
Result := content_type_to_request_format (request_content_type (content_type_supported))
|
Result := content_type_to_request_format (request_content_type (content_type_supported))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
request_format_id (a_format_variable_name: detachable STRING; content_type_supported: detachable ARRAY [STRING]): INTEGER
|
request_format_id (a_format_variable_name: detachable READABLE_STRING_GENERAL; content_type_supported: detachable ARRAY [READABLE_STRING_8]): INTEGER
|
||||||
-- Format id for the request based on {HTTP_FORMAT_CONSTANTS}
|
-- Format id for the request based on {HTTP_FORMAT_CONSTANTS}
|
||||||
do
|
do
|
||||||
if attached request_format (a_format_variable_name, content_type_supported) as l_format then
|
if attached request_format (a_format_variable_name, content_type_supported) as l_format then
|
||||||
Result := format_id (l_format)
|
Result := Format_constants.format_id (l_format)
|
||||||
else
|
else
|
||||||
Result := 0
|
Result := 0
|
||||||
end
|
end
|
||||||
@@ -68,7 +70,7 @@ feature -- Access
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
request_content_type (content_type_supported: detachable ARRAY [STRING]): detachable READABLE_STRING_8
|
request_content_type (content_type_supported: detachable ARRAY [READABLE_STRING_8]): detachable READABLE_STRING_8
|
||||||
local
|
local
|
||||||
s: detachable READABLE_STRING_32
|
s: detachable READABLE_STRING_32
|
||||||
i,n: INTEGER
|
i,n: INTEGER
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
note
|
||||||
|
description: "Summary description for {DEFAULT_REQUEST_URI_TEMPLATE_ROUTING_HANDLER}."
|
||||||
|
author: ""
|
||||||
|
date: "$Date$"
|
||||||
|
revision: "$Revision$"
|
||||||
|
|
||||||
|
class
|
||||||
|
DEFAULT_REQUEST_URI_TEMPLATE_ROUTING_HANDLER
|
||||||
|
|
||||||
|
inherit
|
||||||
|
REQUEST_URI_TEMPLATE_ROUTING_HANDLER [REQUEST_HANDLER [REQUEST_URI_TEMPLATE_HANDLER_CONTEXT], REQUEST_URI_TEMPLATE_HANDLER_CONTEXT]
|
||||||
|
redefine
|
||||||
|
router
|
||||||
|
end
|
||||||
|
|
||||||
|
create
|
||||||
|
make
|
||||||
|
|
||||||
|
feature {NONE} -- Routing
|
||||||
|
|
||||||
|
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
|
||||||
@@ -37,7 +37,7 @@ feature -- Status report
|
|||||||
|
|
||||||
feature -- Execution
|
feature -- Execution
|
||||||
|
|
||||||
execute (a_hdl_context: C; req: WGI_REQUEST; res: WGI_RESPONSE_BUFFER)
|
execute (ctx: 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)
|
||||||
@@ -46,42 +46,42 @@ feature -- Execution
|
|||||||
do
|
do
|
||||||
if not rescued then
|
if not rescued then
|
||||||
if request_method_name_supported (req.request_method) then
|
if request_method_name_supported (req.request_method) then
|
||||||
pre_execute (req)
|
pre_execute (ctx, req, res)
|
||||||
execute_application (a_hdl_context, req, res)
|
execute_application (ctx, req, res)
|
||||||
post_execute (req, res)
|
post_execute (ctx, req, res)
|
||||||
else
|
else
|
||||||
execute_request_method_not_allowed (req, res, supported_request_method_names)
|
execute_request_method_not_allowed (req, res, supported_request_method_names)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
rescue_execute (req, res)
|
rescue_execute (ctx, req, res)
|
||||||
end
|
end
|
||||||
rescue
|
rescue
|
||||||
rescued := True
|
rescued := True
|
||||||
retry
|
retry
|
||||||
end
|
end
|
||||||
|
|
||||||
execute_application (a_hdl_context: C; req: WGI_REQUEST; res: WGI_RESPONSE_BUFFER)
|
execute_application (ctx: C; req: WGI_REQUEST; res: WGI_RESPONSE_BUFFER)
|
||||||
-- Execute request handler
|
-- Execute request handler
|
||||||
deferred
|
deferred
|
||||||
end
|
end
|
||||||
|
|
||||||
pre_execute (req: WGI_REQUEST)
|
pre_execute (ctx: C; req: WGI_REQUEST; res: WGI_RESPONSE_BUFFER)
|
||||||
-- Operation processed before `execute'
|
-- Operation processed before `execute'
|
||||||
do
|
do
|
||||||
--| To be redefined if needed
|
--| To be redefined if needed
|
||||||
end
|
end
|
||||||
|
|
||||||
post_execute (req: WGI_REQUEST; res: WGI_RESPONSE_BUFFER)
|
post_execute (ctx: C; req: WGI_REQUEST; res: WGI_RESPONSE_BUFFER)
|
||||||
-- Operation processed after `execute'
|
-- Operation processed after `execute'
|
||||||
do
|
do
|
||||||
--| To be redefined if needed
|
--| To be redefined if needed
|
||||||
end
|
end
|
||||||
|
|
||||||
rescue_execute (req: WGI_REQUEST; res: WGI_RESPONSE_BUFFER)
|
rescue_execute (ctx: C; req: WGI_REQUEST; res: WGI_RESPONSE_BUFFER)
|
||||||
-- Operation processed after a rescue
|
-- Operation processed after a rescue
|
||||||
do
|
do
|
||||||
--| To be redefined if needed
|
--| To be redefined if needed
|
||||||
post_execute (req, res)
|
post_execute (ctx, req, res)
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Execution: report
|
feature -- Execution: report
|
||||||
|
|||||||
@@ -0,0 +1,73 @@
|
|||||||
|
note
|
||||||
|
description: "Summary description for {REQUEST_ROUTING_HANDLER}."
|
||||||
|
author: ""
|
||||||
|
date: "$Date$"
|
||||||
|
revision: "$Revision$"
|
||||||
|
|
||||||
|
deferred class
|
||||||
|
REQUEST_ROUTING_HANDLER [H -> REQUEST_HANDLER [C],
|
||||||
|
C -> REQUEST_HANDLER_CONTEXT]
|
||||||
|
|
||||||
|
inherit
|
||||||
|
REQUEST_HANDLER [C]
|
||||||
|
|
||||||
|
feature -- Execution
|
||||||
|
|
||||||
|
execute_application (ctx: C; req: WGI_REQUEST; res: WGI_RESPONSE_BUFFER)
|
||||||
|
-- Execute request handler
|
||||||
|
local
|
||||||
|
hdl: detachable H
|
||||||
|
do
|
||||||
|
hdl := router.dispatch_and_return_handler (req, res)
|
||||||
|
end
|
||||||
|
|
||||||
|
feature {NONE} -- Routing
|
||||||
|
|
||||||
|
router: REQUEST_ROUTER [H, C]
|
||||||
|
deferred
|
||||||
|
end
|
||||||
|
|
||||||
|
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
|
||||||
|
router.map (a_resource, h)
|
||||||
|
end
|
||||||
|
|
||||||
|
map_with_request_methods (a_resource: READABLE_STRING_8; h: H; rqst_methods: detachable ARRAY [READABLE_STRING_8])
|
||||||
|
-- Map handler `h' with `a_resource' and `rqst_methods'
|
||||||
|
do
|
||||||
|
router.map_with_request_methods (a_resource, h, rqst_methods)
|
||||||
|
end
|
||||||
|
|
||||||
|
map_agent (a_resource: READABLE_STRING_8; a_action: PROCEDURE [ANY, TUPLE [ctx: C; req: WGI_REQUEST; res: WGI_RESPONSE_BUFFER]])
|
||||||
|
do
|
||||||
|
router.map_agent (a_resource, a_action)
|
||||||
|
end
|
||||||
|
|
||||||
|
map_agent_with_request_methods (a_resource: READABLE_STRING_8; a_action: PROCEDURE [ANY, TUPLE [ctx: C; req: WGI_REQUEST; res: WGI_RESPONSE_BUFFER]];
|
||||||
|
rqst_methods: detachable ARRAY [READABLE_STRING_8])
|
||||||
|
do
|
||||||
|
router.map_agent_with_request_methods (a_resource, a_action, 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
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
note
|
||||||
|
description: "Summary description for {REQUEST_ROUTING_HANDLER}."
|
||||||
|
author: ""
|
||||||
|
date: "$Date$"
|
||||||
|
revision: "$Revision$"
|
||||||
|
|
||||||
|
class
|
||||||
|
REQUEST_URI_ROUTING_HANDLER [H -> REQUEST_HANDLER [C],
|
||||||
|
C -> REQUEST_URI_HANDLER_CONTEXT create make end]
|
||||||
|
|
||||||
|
inherit
|
||||||
|
REQUEST_ROUTING_HANDLER [H, C]
|
||||||
|
|
||||||
|
create
|
||||||
|
make
|
||||||
|
|
||||||
|
feature {NONE} -- Initialization
|
||||||
|
|
||||||
|
make (n: INTEGER)
|
||||||
|
do
|
||||||
|
create router.make (n)
|
||||||
|
end
|
||||||
|
|
||||||
|
feature {NONE} -- Routing
|
||||||
|
|
||||||
|
router: REQUEST_URI_ROUTER [H, C]
|
||||||
|
|
||||||
|
;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
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
note
|
||||||
|
description: "Summary description for {REQUEST_ROUTING_HANDLER}."
|
||||||
|
author: ""
|
||||||
|
date: "$Date$"
|
||||||
|
revision: "$Revision$"
|
||||||
|
|
||||||
|
class
|
||||||
|
REQUEST_URI_TEMPLATE_ROUTING_HANDLER [H -> REQUEST_HANDLER [C],
|
||||||
|
C -> REQUEST_URI_TEMPLATE_HANDLER_CONTEXT create make end]
|
||||||
|
|
||||||
|
inherit
|
||||||
|
REQUEST_ROUTING_HANDLER [H, C]
|
||||||
|
|
||||||
|
create
|
||||||
|
make
|
||||||
|
|
||||||
|
feature {NONE} -- Initialization
|
||||||
|
|
||||||
|
make (n: INTEGER)
|
||||||
|
do
|
||||||
|
create router.make (n)
|
||||||
|
end
|
||||||
|
|
||||||
|
feature {NONE} -- Routing
|
||||||
|
|
||||||
|
router: REQUEST_URI_TEMPLATE_ROUTER [H, C]
|
||||||
|
|
||||||
|
;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
|
||||||
@@ -9,38 +9,44 @@ deferred class
|
|||||||
|
|
||||||
feature -- Mapping
|
feature -- Mapping
|
||||||
|
|
||||||
map_default (r: like default_handler)
|
map_default (h: like default_handler)
|
||||||
-- Map default handler
|
-- Map default handler
|
||||||
-- If no route/handler is found,
|
-- If no route/handler is found,
|
||||||
-- then use `default_handler' as default if not Void
|
-- then use `default_handler' as default if not Void
|
||||||
do
|
do
|
||||||
set_default_handler (r)
|
set_default_handler (h)
|
||||||
end
|
end
|
||||||
|
|
||||||
map (a_id: READABLE_STRING_8; h: H)
|
map (a_resource: READABLE_STRING_8; h: H)
|
||||||
-- Map handler `h' with `a_id'
|
-- Map handler `h' with `a_resource'
|
||||||
do
|
do
|
||||||
map_with_request_methods (a_id, h, Void)
|
map_with_request_methods (a_resource, h, Void)
|
||||||
end
|
end
|
||||||
|
|
||||||
map_with_request_methods (a_id: READABLE_STRING_8; h: H; rqst_methods: detachable ARRAY [READABLE_STRING_8])
|
map_routing (a_resource: READABLE_STRING_8; h: H)
|
||||||
-- Map handler `h' with `a_id' and `rqst_methods'
|
-- Map handler `h' with `a_resource'
|
||||||
|
do
|
||||||
|
map (a_resource, h)
|
||||||
|
end
|
||||||
|
|
||||||
|
map_with_request_methods (a_resource: READABLE_STRING_8; h: H; rqst_methods: detachable ARRAY [READABLE_STRING_8])
|
||||||
|
-- Map handler `h' with `a_resource' and `rqst_methods'
|
||||||
deferred
|
deferred
|
||||||
end
|
end
|
||||||
|
|
||||||
map_agent (a_id: READABLE_STRING_8; a_action: PROCEDURE [ANY, TUPLE [ctx: C; req: WGI_REQUEST; res: WGI_RESPONSE_BUFFER]])
|
map_agent (a_resource: 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_resource, a_action, Void)
|
||||||
end
|
end
|
||||||
|
|
||||||
map_agent_with_request_methods (a_id: READABLE_STRING_8; a_action: PROCEDURE [ANY, TUPLE [ctx: C; req: WGI_REQUEST; res: WGI_RESPONSE_BUFFER]];
|
map_agent_with_request_methods (a_resource: READABLE_STRING_8; a_action: PROCEDURE [ANY, TUPLE [ctx: C; req: WGI_REQUEST; res: WGI_RESPONSE_BUFFER]];
|
||||||
rqst_methods: detachable ARRAY [READABLE_STRING_8])
|
rqst_methods: detachable ARRAY [READABLE_STRING_8])
|
||||||
local
|
local
|
||||||
rah: REQUEST_AGENT_HANDLER [C]
|
rah: REQUEST_AGENT_HANDLER [C]
|
||||||
do
|
do
|
||||||
create rah.make (a_action)
|
create rah.make (a_action)
|
||||||
if attached {H} rah as h then
|
if attached {H} rah as h then
|
||||||
map_with_request_methods (a_id, h, rqst_methods)
|
map_with_request_methods (a_resource, h, rqst_methods)
|
||||||
else
|
else
|
||||||
check valid_agent_handler: False end
|
check valid_agent_handler: False end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ feature -- Registration
|
|||||||
create uri.make (tpl)
|
create uri.make (tpl)
|
||||||
map_with_uri_template_and_request_methods (uri, h, rqst_methods)
|
map_with_uri_template_and_request_methods (uri, h, rqst_methods)
|
||||||
end
|
end
|
||||||
|
|
||||||
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: attached like default_handler; context: like default_handler_context]
|
||||||
@@ -51,6 +51,7 @@ feature {NONE} -- Access: Implementation
|
|||||||
t: STRING
|
t: STRING
|
||||||
p: STRING
|
p: STRING
|
||||||
l_req_method: READABLE_STRING_GENERAL
|
l_req_method: READABLE_STRING_GENERAL
|
||||||
|
l_res: URI_TEMPLATE_MATCH_RESULT
|
||||||
do
|
do
|
||||||
p := req.request_uri
|
p := req.request_uri
|
||||||
from
|
from
|
||||||
@@ -63,7 +64,15 @@ feature {NONE} -- Access: Implementation
|
|||||||
if attached l_handlers.item as l_info then
|
if attached l_handlers.item as l_info then
|
||||||
if is_matching_request_methods (l_req_method, l_info.request_methods) then
|
if is_matching_request_methods (l_req_method, l_info.request_methods) then
|
||||||
t := l_info.resource
|
t := l_info.resource
|
||||||
if attached templates.item (t) as tpl and then
|
if
|
||||||
|
attached {REQUEST_ROUTING_HANDLER [H, C]} l_info.handler as rah and then
|
||||||
|
p.starts_with (t)
|
||||||
|
then
|
||||||
|
create l_res.make_empty
|
||||||
|
l_res.path_variables.force (p.substring (t.count, p.count), "path")
|
||||||
|
|
||||||
|
Result := [l_info.handler, handler_context (p, req, create {URI_TEMPLATE}.make (t), l_res)]
|
||||||
|
elseif attached templates.item (t) as tpl and then
|
||||||
attached tpl.match (p) as res
|
attached tpl.match (p) as res
|
||||||
then
|
then
|
||||||
Result := [l_info.handler, handler_context (p, req, tpl, res)]
|
Result := [l_info.handler, handler_context (p, req, tpl, res)]
|
||||||
|
|||||||
Reference in New Issue
Block a user