Added assertions to catch if route mapping does not already exists
This commit is contained in:
@@ -10,6 +10,21 @@ deferred class
|
||||
inherit
|
||||
ITERABLE [TUPLE [handler: H; resource: READABLE_STRING_8; request_methods: detachable ARRAY [READABLE_STRING_8]]]
|
||||
|
||||
feature -- Status report
|
||||
|
||||
has_map (a_resource: READABLE_STRING_8; rqst_methods: detachable ARRAY [READABLE_STRING_8]; a_handler: detachable H): BOOLEAN
|
||||
-- Has a map corresponding to `a_resource' and `rqst_methods' other than `a_handler'?
|
||||
do
|
||||
if attached handlers_matching_map (a_resource, rqst_methods) as lst then
|
||||
Result := a_handler = Void or else not lst.has (a_handler)
|
||||
end
|
||||
end
|
||||
|
||||
handlers_matching_map (a_resource: READABLE_STRING_8; rqst_methods: detachable ARRAY [READABLE_STRING_8]): detachable LIST [H]
|
||||
-- Existing handlers matching map with `a_resource' and `rqst_methods'
|
||||
deferred
|
||||
end
|
||||
|
||||
feature -- Mapping
|
||||
|
||||
map_default (h: like default_handler)
|
||||
@@ -22,18 +37,24 @@ feature -- Mapping
|
||||
|
||||
map (a_resource: READABLE_STRING_8; h: H)
|
||||
-- Map handler `h' with `a_resource'
|
||||
require
|
||||
has_not_such_map: not has_map (a_resource, Void, h)
|
||||
do
|
||||
map_with_request_methods (a_resource, h, Void)
|
||||
end
|
||||
|
||||
map_routing (a_resource: READABLE_STRING_8; h: H)
|
||||
-- Map handler `h' with `a_resource'
|
||||
require
|
||||
has_not_such_map: not has_map (a_resource, Void, h)
|
||||
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'
|
||||
require
|
||||
has_not_such_map: not has_map (a_resource, rqst_methods, h)
|
||||
deferred
|
||||
end
|
||||
|
||||
|
||||
@@ -30,6 +30,30 @@ feature -- Initialization
|
||||
set_base_url (a_base_url)
|
||||
end
|
||||
|
||||
feature -- Status report
|
||||
|
||||
handlers_matching_map (a_resource: READABLE_STRING_8; rqst_methods: detachable ARRAY [READABLE_STRING_8]): detachable LIST [H]
|
||||
local
|
||||
l_res: READABLE_STRING_8
|
||||
do
|
||||
l_res := based_resource (a_resource)
|
||||
across
|
||||
handlers as c
|
||||
loop
|
||||
if c.item.resource.same_string (l_res) then
|
||||
if
|
||||
rqst_methods = Void or else
|
||||
across rqst_methods as rq some is_matching_request_methods (rq.item, c.item.request_methods) end
|
||||
then
|
||||
if Result = Void then
|
||||
create {ARRAYED_LIST [H]} Result.make (1)
|
||||
end
|
||||
Result.extend (c.item.handler)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
feature -- Registration
|
||||
|
||||
map_with_request_methods (p: READABLE_STRING_8; h: H; rqst_methods: detachable ARRAY [READABLE_STRING_8])
|
||||
@@ -45,6 +69,17 @@ feature -- Registration
|
||||
h.on_handler_mapped (l_uri, rqst_methods)
|
||||
end
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
based_resource (a_resource: READABLE_STRING_8): READABLE_STRING_8
|
||||
do
|
||||
if attached base_url as l_base_url then
|
||||
Result := l_base_url + a_resource
|
||||
else
|
||||
Result := a_resource
|
||||
end
|
||||
end
|
||||
|
||||
feature {NONE} -- Access: Implementation
|
||||
|
||||
handler (req: WSF_REQUEST): detachable TUPLE [handler: H; context: like default_handler_context]
|
||||
|
||||
@@ -31,9 +31,35 @@ feature -- Initialization
|
||||
set_base_url (a_base_url)
|
||||
end
|
||||
|
||||
feature -- Status report
|
||||
|
||||
handlers_matching_map (a_resource: READABLE_STRING_8; rqst_methods: detachable ARRAY [READABLE_STRING_8]): detachable LIST [H]
|
||||
local
|
||||
l_res: READABLE_STRING_8
|
||||
do
|
||||
l_res := based_resource (a_resource)
|
||||
across
|
||||
handlers as c
|
||||
loop
|
||||
if c.item.resource.same_string (l_res) then
|
||||
if
|
||||
rqst_methods = Void or else
|
||||
across rqst_methods as rq some is_matching_request_methods (rq.item, c.item.request_methods) end
|
||||
then
|
||||
if Result = Void then
|
||||
create {ARRAYED_LIST [H]} Result.make (1)
|
||||
end
|
||||
Result.extend (c.item.handler)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
feature -- Registration
|
||||
|
||||
map_with_uri_template (uri: URI_TEMPLATE; h: H)
|
||||
require
|
||||
has_not_such_map: not has_map (uri.template, Void, h)
|
||||
do
|
||||
map_with_uri_template_and_request_methods (uri, h, Void)
|
||||
end
|
||||
@@ -41,17 +67,13 @@ feature -- Registration
|
||||
map_with_uri_template_and_request_methods (uri: URI_TEMPLATE; h: H; rqst_methods: detachable ARRAY [READABLE_STRING_8])
|
||||
require
|
||||
uri_is_valid: uri.is_valid
|
||||
has_not_such_map: not has_map (uri.template, rqst_methods, h)
|
||||
local
|
||||
l_tpl: like {URI_TEMPLATE}.template
|
||||
l_uri: URI_TEMPLATE
|
||||
do
|
||||
l_uri := uri
|
||||
l_uri := based_uri (uri)
|
||||
l_tpl := l_uri.template
|
||||
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)
|
||||
@@ -63,7 +85,28 @@ feature -- Registration
|
||||
map_with_uri_template_and_request_methods (create {URI_TEMPLATE}.make (tpl), h, rqst_methods)
|
||||
end
|
||||
|
||||
feature {ROUTED_SERVICE_I} -- Hanlder
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
based_uri (uri: URI_TEMPLATE): URI_TEMPLATE
|
||||
do
|
||||
if attached base_url as l_base_url then
|
||||
Result := uri.duplicate
|
||||
Result.set_template (l_base_url + uri.template)
|
||||
else
|
||||
Result := uri
|
||||
end
|
||||
end
|
||||
|
||||
based_resource (a_resource: READABLE_STRING_8): READABLE_STRING_8
|
||||
do
|
||||
if attached base_url as l_base_url then
|
||||
Result := l_base_url + a_resource
|
||||
else
|
||||
Result := a_resource
|
||||
end
|
||||
end
|
||||
|
||||
feature {ROUTED_SERVICE_I} -- Handler
|
||||
|
||||
handler (req: WSF_REQUEST): detachable TUPLE [handler: attached like default_handler; context: like default_handler_context]
|
||||
local
|
||||
|
||||
Reference in New Issue
Block a user