Added `base_url' for REQUEST_ROUTER (and descendants)
Fixed implementation of REST_REQUEST_AGENT_HANDLER to avoid wrong path in inherited routine. Allow to build a URI_TEMPLATE from another URI TEMPLATE, this way, if later we have more attribute (status or settings) to URI_TEMPLATE, we'll be able to change the `template' without breaking the settings
This commit is contained in:
@@ -23,18 +23,44 @@ inherit
|
|||||||
create
|
create
|
||||||
make
|
make
|
||||||
|
|
||||||
|
create {URI_TEMPLATE}
|
||||||
|
make_from_uri_template
|
||||||
|
|
||||||
|
convert
|
||||||
|
make ({READABLE_STRING_8})
|
||||||
|
|
||||||
feature {NONE} -- Initialization
|
feature {NONE} -- Initialization
|
||||||
|
|
||||||
make (s: STRING)
|
make (s: READABLE_STRING_8)
|
||||||
do
|
do
|
||||||
template := s
|
template := s
|
||||||
end
|
end
|
||||||
|
|
||||||
|
make_from_uri_template (a_tpl: like Current)
|
||||||
|
do
|
||||||
|
template := a_tpl.template.string
|
||||||
|
end
|
||||||
|
|
||||||
feature -- Access
|
feature -- Access
|
||||||
|
|
||||||
template: STRING
|
template: READABLE_STRING_8
|
||||||
-- URI string representation
|
-- URI string representation
|
||||||
|
|
||||||
|
duplicate: like Current
|
||||||
|
-- Duplicate object from Current
|
||||||
|
do
|
||||||
|
create Result.make_from_uri_template (Current)
|
||||||
|
end
|
||||||
|
|
||||||
|
feature -- Element change
|
||||||
|
|
||||||
|
set_template (t: like template)
|
||||||
|
-- Set `template' to `t'
|
||||||
|
do
|
||||||
|
template := t
|
||||||
|
reset
|
||||||
|
end
|
||||||
|
|
||||||
feature -- Status report
|
feature -- Status report
|
||||||
|
|
||||||
debug_output: STRING
|
debug_output: STRING
|
||||||
|
|||||||
@@ -9,14 +9,15 @@ class
|
|||||||
|
|
||||||
inherit
|
inherit
|
||||||
REQUEST_AGENT_HANDLER [C]
|
REQUEST_AGENT_HANDLER [C]
|
||||||
redefine
|
rename
|
||||||
execute
|
execute as execute_application
|
||||||
end
|
end
|
||||||
|
|
||||||
REST_REQUEST_HANDLER [C]
|
REST_REQUEST_HANDLER [C]
|
||||||
redefine
|
select
|
||||||
execute
|
execute
|
||||||
end
|
end
|
||||||
|
|
||||||
create
|
create
|
||||||
make
|
make
|
||||||
|
|
||||||
@@ -38,26 +39,6 @@ feature {NONE} -- Implementation
|
|||||||
|
|
||||||
internal_authentication_required: BOOLEAN
|
internal_authentication_required: BOOLEAN
|
||||||
|
|
||||||
feature -- Execution
|
|
||||||
|
|
||||||
execute (ctx: C; req: WGI_REQUEST; res: WGI_RESPONSE_BUFFER)
|
|
||||||
do
|
|
||||||
if
|
|
||||||
authentication_required (req) and then not authenticated (ctx)
|
|
||||||
then
|
|
||||||
execute_unauthorized (ctx, req, res)
|
|
||||||
else
|
|
||||||
pre_execute (ctx, req, res)
|
|
||||||
Precursor {REQUEST_AGENT_HANDLER} (ctx, req, res)
|
|
||||||
post_execute (ctx, req, res)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
execute_application (ctx: C; req: WGI_REQUEST; res: WGI_RESPONSE_BUFFER)
|
|
||||||
do
|
|
||||||
check should_not_occur: False end
|
|
||||||
end
|
|
||||||
|
|
||||||
;note
|
;note
|
||||||
copyright: "Copyright (c) 1984-2011, Eiffel Software and others"
|
copyright: "Copyright (c) 1984-2011, 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)"
|
||||||
|
|||||||
@@ -52,6 +52,17 @@ feature -- Mapping
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
feature -- Base url
|
||||||
|
|
||||||
|
base_url: detachable READABLE_STRING_8
|
||||||
|
-- Common start of any route url
|
||||||
|
|
||||||
|
set_base_url (a_base_url: like base_url)
|
||||||
|
-- Set `base_url' to `a_base_url'
|
||||||
|
do
|
||||||
|
base_url := a_base_url
|
||||||
|
end
|
||||||
|
|
||||||
feature -- Execution
|
feature -- Execution
|
||||||
|
|
||||||
dispatch (req: WGI_REQUEST; res: WGI_RESPONSE_BUFFER): BOOLEAN
|
dispatch (req: WGI_REQUEST; res: WGI_RESPONSE_BUFFER): BOOLEAN
|
||||||
@@ -97,13 +108,19 @@ feature -- Traversing
|
|||||||
|
|
||||||
feature {NONE} -- Access: Implementation
|
feature {NONE} -- Access: Implementation
|
||||||
|
|
||||||
|
source_uri (req: WGI_REQUEST): READABLE_STRING_32
|
||||||
|
-- URI to use to find handler.
|
||||||
|
do
|
||||||
|
Result := req.path_info
|
||||||
|
end
|
||||||
|
|
||||||
handler (req: WGI_REQUEST): detachable TUPLE [handler: H; 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: source_uri (req) /= Void
|
||||||
deferred
|
deferred
|
||||||
ensure
|
ensure
|
||||||
req_path_info_unchanged: req.path_info.same_string (old req.path_info)
|
source_uri_unchanged: source_uri (req).same_string (old source_uri (req))
|
||||||
end
|
end
|
||||||
|
|
||||||
is_matching_request_methods (a_request_method: READABLE_STRING_GENERAL; rqst_methods: like formatted_request_methods): BOOLEAN
|
is_matching_request_methods (a_request_method: READABLE_STRING_GENERAL; rqst_methods: like formatted_request_methods): BOOLEAN
|
||||||
|
|||||||
@@ -24,9 +24,16 @@ feature -- Initialization
|
|||||||
feature -- Registration
|
feature -- Registration
|
||||||
|
|
||||||
map_with_request_methods (p: READABLE_STRING_8; h: H; rqst_methods: detachable ARRAY [READABLE_STRING_8])
|
map_with_request_methods (p: READABLE_STRING_8; h: H; rqst_methods: detachable ARRAY [READABLE_STRING_8])
|
||||||
|
local
|
||||||
|
l_uri: READABLE_STRING_8
|
||||||
do
|
do
|
||||||
handlers.force ([h, p, formatted_request_methods (rqst_methods)])
|
if attached base_url as l_base_url then
|
||||||
h.on_handler_mapped (p, rqst_methods)
|
l_uri := l_base_url + p
|
||||||
|
else
|
||||||
|
l_uri := p
|
||||||
|
end
|
||||||
|
handlers.force ([h, l_uri, formatted_request_methods (rqst_methods)])
|
||||||
|
h.on_handler_mapped (l_uri, rqst_methods)
|
||||||
end
|
end
|
||||||
|
|
||||||
feature {NONE} -- Access: Implementation
|
feature {NONE} -- Access: Implementation
|
||||||
@@ -36,9 +43,9 @@ feature {NONE} -- Access: Implementation
|
|||||||
h: detachable H
|
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 (source_uri (req), req.request_method)
|
||||||
if h = Void then
|
if h = Void then
|
||||||
if attached smart_handler_by_path (req.path_info, req.request_method) as info then
|
if attached smart_handler_by_path (source_uri (req), req.request_method) as info then
|
||||||
h := info.handler
|
h := info.handler
|
||||||
ctx := handler_context (info.path, req)
|
ctx := handler_context (info.path, req)
|
||||||
end
|
end
|
||||||
@@ -57,11 +64,11 @@ feature {NONE} -- Access: Implementation
|
|||||||
|
|
||||||
smart_handler (req: WGI_REQUEST): detachable TUPLE [path: READABLE_STRING_8; handler: H]
|
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 source_uri (req) /= Void
|
||||||
do
|
do
|
||||||
Result := smart_handler_by_path (req.path_info, req.request_method)
|
Result := smart_handler_by_path (source_uri (req), req.request_method)
|
||||||
ensure
|
ensure
|
||||||
req_path_info_unchanged: req.path_info.same_string (old req.path_info)
|
req_path_info_unchanged: source_uri (req).same_string (old source_uri (req))
|
||||||
end
|
end
|
||||||
|
|
||||||
handler_by_path (a_path: READABLE_STRING_GENERAL; rqst_method: READABLE_STRING_GENERAL): detachable H
|
handler_by_path (a_path: READABLE_STRING_GENERAL; rqst_method: READABLE_STRING_GENERAL): detachable H
|
||||||
@@ -124,7 +131,7 @@ feature {NONE} -- Context factory
|
|||||||
if p /= Void then
|
if p /= Void then
|
||||||
create ctx.make (req, p)
|
create ctx.make (req, p)
|
||||||
else
|
else
|
||||||
create ctx.make (req, req.path_info)
|
create ctx.make (req, source_uri (req))
|
||||||
end
|
end
|
||||||
Result := ctx
|
Result := ctx
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -30,18 +30,26 @@ feature -- Registration
|
|||||||
end
|
end
|
||||||
|
|
||||||
map_with_uri_template_and_request_methods (uri: URI_TEMPLATE; h: H; 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])
|
||||||
|
local
|
||||||
|
l_tpl: like {URI_TEMPLATE}.template
|
||||||
|
l_uri: URI_TEMPLATE
|
||||||
do
|
do
|
||||||
handlers.force ([h, uri.template, formatted_request_methods (rqst_methods)])
|
l_uri := uri
|
||||||
templates.force (uri, uri.template)
|
l_tpl := l_uri.template
|
||||||
h.on_handler_mapped (uri.template, rqst_methods)
|
if attached base_url as l_base_url then
|
||||||
|
l_uri := l_uri.duplicate
|
||||||
|
l_uri.set_template (l_base_url + l_tpl)
|
||||||
|
l_tpl := l_uri.template
|
||||||
|
end
|
||||||
|
|
||||||
|
handlers.force ([h, l_tpl, formatted_request_methods (rqst_methods)])
|
||||||
|
templates.force (l_uri, l_tpl)
|
||||||
|
h.on_handler_mapped (l_tpl, rqst_methods)
|
||||||
end
|
end
|
||||||
|
|
||||||
map_with_request_methods (tpl: READABLE_STRING_8; h: H; 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
|
|
||||||
uri: URI_TEMPLATE
|
|
||||||
do
|
do
|
||||||
create uri.make (tpl)
|
map_with_uri_template_and_request_methods (create {URI_TEMPLATE}.make (tpl), h, rqst_methods)
|
||||||
map_with_uri_template_and_request_methods (uri, h, rqst_methods)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
feature {NONE} -- Access: Implementation
|
feature {NONE} -- Access: Implementation
|
||||||
@@ -54,7 +62,7 @@ feature {NONE} -- Access: Implementation
|
|||||||
l_req_method: READABLE_STRING_GENERAL
|
l_req_method: READABLE_STRING_GENERAL
|
||||||
l_res: URI_TEMPLATE_MATCH_RESULT
|
l_res: URI_TEMPLATE_MATCH_RESULT
|
||||||
do
|
do
|
||||||
p := req.path_info
|
p := source_uri (req)
|
||||||
from
|
from
|
||||||
l_req_method := req.request_method
|
l_req_method := req.request_method
|
||||||
l_handlers := handlers
|
l_handlers := handlers
|
||||||
@@ -70,7 +78,7 @@ feature {NONE} -- Access: Implementation
|
|||||||
p.starts_with (t)
|
p.starts_with (t)
|
||||||
then
|
then
|
||||||
create l_res.make_empty
|
create l_res.make_empty
|
||||||
l_res.path_variables.force (p.substring (t.count, p.count), "path")
|
l_res.path_variables.force (p.substring (t.count + 1, p.count), "path")
|
||||||
|
|
||||||
Result := [l_info.handler, handler_context (p, req, create {URI_TEMPLATE}.make (t), l_res)]
|
Result := [l_info.handler, handler_context (p, req, create {URI_TEMPLATE}.make (t), l_res)]
|
||||||
elseif attached templates.item (t) as tpl and then
|
elseif attached templates.item (t) as tpl and then
|
||||||
@@ -91,7 +99,7 @@ feature {NONE} -- Context factory
|
|||||||
if p /= Void then
|
if p /= Void then
|
||||||
create Result.make (req, tpl, tpl_res, p)
|
create Result.make (req, tpl, tpl_res, p)
|
||||||
else
|
else
|
||||||
create Result.make (req, tpl, tpl_res, req.path_info)
|
create Result.make (req, tpl, tpl_res, source_uri (req))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -144,11 +152,8 @@ feature {NONE} -- Default: implementation
|
|||||||
end
|
end
|
||||||
|
|
||||||
default_handler_context (req: WGI_REQUEST): C
|
default_handler_context (req: WGI_REQUEST): C
|
||||||
local
|
|
||||||
tpl: URI_TEMPLATE
|
|
||||||
do
|
do
|
||||||
create tpl.make ("/")
|
Result := handler_context (Void, req, create {URI_TEMPLATE}.make ("/"), create {URI_TEMPLATE_MATCH_RESULT}.make_empty)
|
||||||
Result := handler_context ("/", req, tpl, create {URI_TEMPLATE_MATCH_RESULT}.make_empty)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
;note
|
;note
|
||||||
|
|||||||
Reference in New Issue
Block a user