Adopted convention name and value or values for WSF_VALUE and descendant (WSF_STRING ...)

kept `key' as redirection, and also string as obsolete redirection.
Router: provide a way to pass the request methods without using manifest string, thanks to WSF_ROUTER_METHODS
  so instead of using manifest array or manifest strings, just create an instance of WSF_ROUTER_METHODS
  for convenience, WSF_ROUTER provides a few `methods_...' returning prebuilt WSF_ROUTER_METHODS objects
Improved code related to unicode handling in URL, and parameters (before the framework was doing too much)
This commit is contained in:
Jocelyn Fiat
2012-06-11 14:58:13 +02:00
parent 36ed6f525c
commit 8a58d62a7e
29 changed files with 790 additions and 198 deletions

View File

@@ -13,14 +13,14 @@ inherit
redefine
map_agent_with_request_methods, map_agent_response_with_request_methods
end
create
make
feature -- Mapping agent
map_agent_with_request_methods (a_id: READABLE_STRING_8; a_action: PROCEDURE [ANY, TUPLE [ctx: WSF_URI_HANDLER_CONTEXT; req: WSF_REQUEST; res: WSF_RESPONSE]];
rqst_methods: detachable ARRAY [READABLE_STRING_8])
rqst_methods: detachable WSF_ROUTER_METHODS)
local
h: WSF_AGENT_HANDLER [WSF_URI_HANDLER_CONTEXT]
do
@@ -29,7 +29,7 @@ feature -- Mapping agent
end
map_agent_response_with_request_methods (a_id: READABLE_STRING_8; a_action: FUNCTION [ANY, TUPLE [ctx: WSF_URI_HANDLER_CONTEXT; req: WSF_REQUEST], WSF_RESPONSE_MESSAGE];
rqst_methods: detachable ARRAY [READABLE_STRING_8])
rqst_methods: detachable WSF_ROUTER_METHODS)
local
h: WSF_AGENT_RESPONSE_HANDLER [WSF_URI_HANDLER_CONTEXT]
do

View File

@@ -47,7 +47,7 @@ feature -- Initialization
feature {WSF_ROUTED_SERVICE_I} -- Status report
handlers_matching_map (a_resource: READABLE_STRING_8; rqst_methods: detachable ARRAY [READABLE_STRING_8]): detachable LIST [H]
handlers_matching_map (a_resource: READABLE_STRING_8; rqst_methods: detachable WSF_ROUTER_METHODS): detachable LIST [H]
local
l_res: READABLE_STRING_8
do
@@ -79,7 +79,7 @@ feature {WSF_ROUTED_SERVICE_I} -- Default: implementation
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 WSF_ROUTER_METHODS)
local
l_uri: READABLE_STRING_8
do
@@ -88,7 +88,7 @@ feature -- Registration
else
l_uri := p
end
handlers.force ([h, l_uri, formatted_request_methods (rqst_methods)])
handlers.force ([h, l_uri, rqst_methods])
h.on_handler_mapped (l_uri, rqst_methods)
end
@@ -109,10 +109,13 @@ feature {WSF_ROUTED_SERVICE_I} -- Handler
local
h: detachable H
ctx: detachable C
rq_method: READABLE_STRING_8
do
h := handler_by_path (source_uri (req), req.request_method)
rq_method := request_method (req)
h := handler_by_path (source_uri (req), rq_method)
if h = Void then
if attached smart_handler_by_path (source_uri (req), req.request_method) as info then
if attached smart_handler_by_path (source_uri (req), rq_method) as info then
h := info.handler
ctx := handler_context (info.path, req)
end
@@ -131,16 +134,7 @@ feature {WSF_ROUTED_SERVICE_I} -- Handler
feature {NONE} -- Access: Implementation
smart_handler (req: WSF_REQUEST): detachable TUPLE [path: READABLE_STRING_8; handler: H]
require
req_valid: req /= Void and then source_uri (req) /= Void
do
Result := smart_handler_by_path (source_uri (req), req.request_method)
ensure
req_path_info_unchanged: source_uri (req).same_string (old source_uri (req))
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_8): detachable H
require
a_path_valid: a_path /= Void
local
@@ -163,7 +157,7 @@ feature {NONE} -- Access: Implementation
a_path_unchanged: a_path.same_string (old a_path)
end
smart_handler_by_path (a_path: READABLE_STRING_8; rqst_method: READABLE_STRING_GENERAL): detachable TUPLE [path: READABLE_STRING_8; handler: H]
smart_handler_by_path (a_path: READABLE_STRING_8; rqst_method: READABLE_STRING_8): detachable TUPLE [path: READABLE_STRING_8; handler: H]
require
a_path_valid: a_path /= Void
local
@@ -207,7 +201,7 @@ feature {NONE} -- Context factory
feature -- Access
new_cursor: ITERATION_CURSOR [TUPLE [handler: H; 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 WSF_ROUTER_METHODS]]
-- Fresh cursor associated with current structure
do
Result := handlers.new_cursor
@@ -215,7 +209,7 @@ feature -- Access
feature {NONE} -- Implementation
handlers: ARRAYED_LIST [TUPLE [handler: H; resource: READABLE_STRING_8; request_methods: detachable ARRAY [READABLE_STRING_8]]]
handlers: ARRAYED_LIST [TUPLE [handler: H; resource: READABLE_STRING_8; request_methods: detachable WSF_ROUTER_METHODS]]
-- Handlers indexed by the template expression
-- see `templates'

View File

@@ -22,7 +22,7 @@ create
feature -- Mapping agent
map_agent_with_request_methods (a_id: READABLE_STRING_8; a_action: PROCEDURE [ANY, TUPLE [ctx: WSF_URI_TEMPLATE_HANDLER_CONTEXT; req: WSF_REQUEST; res: WSF_RESPONSE]];
rqst_methods: detachable ARRAY [READABLE_STRING_8])
rqst_methods: detachable WSF_ROUTER_METHODS)
local
h: WSF_AGENT_HANDLER [WSF_URI_TEMPLATE_HANDLER_CONTEXT]
do
@@ -31,7 +31,7 @@ feature -- Mapping agent
end
map_agent_response_with_request_methods (a_id: READABLE_STRING_8; a_action: FUNCTION [ANY, TUPLE [ctx: WSF_URI_TEMPLATE_HANDLER_CONTEXT; req: WSF_REQUEST], WSF_RESPONSE_MESSAGE];
rqst_methods: detachable ARRAY [READABLE_STRING_8])
rqst_methods: detachable WSF_ROUTER_METHODS)
local
h: WSF_AGENT_RESPONSE_HANDLER [WSF_URI_TEMPLATE_HANDLER_CONTEXT]
do

View File

@@ -44,7 +44,7 @@ feature -- Initialization
feature -- Status report
handlers_matching_map (a_resource: READABLE_STRING_8; rqst_methods: detachable ARRAY [READABLE_STRING_8]): detachable LIST [H]
handlers_matching_map (a_resource: READABLE_STRING_8; rqst_methods: detachable WSF_ROUTER_METHODS): detachable LIST [H]
local
l_res: READABLE_STRING_8
do
@@ -75,7 +75,7 @@ feature -- Registration
map_with_uri_template_and_request_methods (uri, h, Void)
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 WSF_ROUTER_METHODS)
require
uri_is_valid: uri.is_valid
has_not_such_map: not has_map (uri.template, rqst_methods, h)
@@ -86,12 +86,12 @@ feature -- Registration
l_uri := based_uri (uri)
l_tpl := l_uri.template
handlers.force ([h, l_tpl, formatted_request_methods (rqst_methods)])
handlers.force ([h, l_tpl, rqst_methods])
templates.force (l_uri, l_tpl)
h.on_handler_mapped (l_tpl, rqst_methods)
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 WSF_ROUTER_METHODS)
do
map_with_uri_template_and_request_methods (create {URI_TEMPLATE}.make (tpl), h, rqst_methods)
end
@@ -124,12 +124,12 @@ feature {WSF_ROUTED_SERVICE_I} -- Handler
l_handlers: like handlers
t: READABLE_STRING_8
p: READABLE_STRING_8
l_req_method: READABLE_STRING_GENERAL
l_req_method: READABLE_STRING_8
l_res: URI_TEMPLATE_MATCH_RESULT
do
p := source_uri (req)
from
l_req_method := req.request_method
l_req_method := request_method (req)
l_handlers := handlers
l_handlers.start
until
@@ -178,7 +178,7 @@ feature {NONE} -- Context factory
feature -- Access: ITERABLE
new_cursor: ITERATION_CURSOR [TUPLE [handler: H; 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 WSF_ROUTER_METHODS]]
-- Fresh cursor associated with current structure
do
Result := handlers.new_cursor
@@ -186,7 +186,7 @@ feature -- Access: ITERABLE
feature {NONE} -- Implementation
handlers: ARRAYED_LIST [TUPLE [handler: H; resource: READABLE_STRING_8; request_methods: detachable ARRAY [READABLE_STRING_8]]]
handlers: ARRAYED_LIST [TUPLE [handler: H; resource: READABLE_STRING_8; request_methods: detachable WSF_ROUTER_METHODS]]
-- Handlers indexed by the template expression
-- see `templates'

View File

@@ -67,7 +67,7 @@ feature -- Execution
-- i.e: path of the file system resource if any
do
if attached {WSF_STRING} ctx.item ("path") as v_path then
Result := v_path.string.as_string_8
Result := v_path.value.as_string_8
end
end

View File

@@ -76,7 +76,7 @@ feature -- Execution: report
feature {WSF_ROUTER} -- Routes change
on_handler_mapped (a_resource: READABLE_STRING_8; a_rqst_methods: detachable ARRAY [READABLE_STRING_8])
on_handler_mapped (a_resource: READABLE_STRING_8; a_rqst_methods: detachable WSF_ROUTER_METHODS)
-- Callback called when a router map a route to Current handler
do
end

View File

@@ -10,7 +10,7 @@ deferred class
WSF_ROUTER [H -> WSF_HANDLER [C], C -> WSF_HANDLER_CONTEXT]
inherit
ITERABLE [TUPLE [handler: H; resource: READABLE_STRING_8; request_methods: detachable ARRAY [READABLE_STRING_8]]]
ITERABLE [TUPLE [handler: H; resource: READABLE_STRING_8; request_methods: detachable WSF_ROUTER_METHODS]]
feature {NONE} -- Initialization
@@ -22,7 +22,7 @@ feature {NONE} -- Initialization
feature -- Status report
has_map (a_resource: READABLE_STRING_8; rqst_methods: detachable ARRAY [READABLE_STRING_8]; a_handler: detachable H): BOOLEAN
has_map (a_resource: READABLE_STRING_8; rqst_methods: detachable WSF_ROUTER_METHODS; 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
@@ -30,7 +30,7 @@ feature -- Status report
end
end
handlers_matching_map (a_resource: READABLE_STRING_8; rqst_methods: detachable ARRAY [READABLE_STRING_8]): detachable LIST [H]
handlers_matching_map (a_resource: READABLE_STRING_8; rqst_methods: detachable WSF_ROUTER_METHODS): detachable LIST [H]
-- Existing handlers matching map with `a_resource' and `rqst_methods'
deferred
end
@@ -53,7 +53,7 @@ feature -- Mapping
map (a_resource, h)
end
map_with_request_methods (a_resource: READABLE_STRING_8; h: H; rqst_methods: detachable ARRAY [READABLE_STRING_8])
map_with_request_methods (a_resource: READABLE_STRING_8; h: H; rqst_methods: detachable WSF_ROUTER_METHODS)
-- Map handler `h' with `a_resource' and `rqst_methods'
require
has_not_such_map: not has_map (a_resource, rqst_methods, h)
@@ -69,7 +69,7 @@ feature -- Mapping agent
end
map_agent_with_request_methods (a_resource: READABLE_STRING_8; a_action: PROCEDURE [ANY, TUPLE [ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE]];
rqst_methods: detachable ARRAY [READABLE_STRING_8])
rqst_methods: detachable WSF_ROUTER_METHODS)
-- Map `a_action' as an handler with `a_resource' and `rqst_methods'
local
rah: WSF_AGENT_HANDLER [C]
@@ -91,7 +91,7 @@ feature -- Mapping response agent
end
map_agent_response_with_request_methods (a_resource: READABLE_STRING_8; a_function: FUNCTION [ANY, TUPLE [ctx: C; req: WSF_REQUEST], WSF_RESPONSE_MESSAGE];
rqst_methods: detachable ARRAY [READABLE_STRING_8])
rqst_methods: detachable WSF_ROUTER_METHODS)
-- Map response as Result `a_function' as an handler with `a_resource' and `rqst_methods'
local
rah: WSF_AGENT_RESPONSE_HANDLER [C]
@@ -203,7 +203,7 @@ feature -- status report
feature -- Traversing
new_cursor: ITERATION_CURSOR [TUPLE [handler: H; 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 WSF_ROUTER_METHODS]]
-- Fresh cursor associated with current structure
deferred
end
@@ -225,51 +225,108 @@ feature {WSF_ROUTED_SERVICE_I} -- Handler
source_uri_unchanged: source_uri (req).same_string (old source_uri (req))
end
feature -- Request methods helper
methods_head: WSF_ROUTER_METHODS
once ("THREAD")
create Result
Result.enable_head
Result.lock
end
methods_options: WSF_ROUTER_METHODS
once ("THREAD")
create Result
Result.enable_options
Result.lock
end
methods_get: WSF_ROUTER_METHODS
once ("THREAD")
create Result
Result.enable_get
Result.lock
end
methods_post: WSF_ROUTER_METHODS
once ("THREAD")
create Result
Result.enable_post
Result.lock
end
methods_put: WSF_ROUTER_METHODS
once ("THREAD")
create Result
Result.enable_put
Result.lock
end
methods_delete: WSF_ROUTER_METHODS
once ("THREAD")
create Result
Result.enable_delete
Result.lock
end
methods_get_post: WSF_ROUTER_METHODS
once ("THREAD")
create Result.make (2)
Result.enable_get
Result.enable_post
Result.lock
end
methods_put_post: WSF_ROUTER_METHODS
once ("THREAD")
create Result.make (2)
Result.enable_put
Result.enable_post
Result.lock
end
feature {NONE} -- Access: Implementation
is_matching_request_methods (a_request_method: READABLE_STRING_GENERAL; a_rqst_methods: like formatted_request_methods): BOOLEAN
-- `a_request_method' is matching `a_rqst_methods' contents
request_method (req: WSF_REQUEST): READABLE_STRING_8
-- Request method from `req' to be used in the router implementation.
local
i,n: INTEGER
m: READABLE_STRING_GENERAL
m: READABLE_STRING_8
do
m := req.request_method
if m.is_case_insensitive_equal ({HTTP_REQUEST_METHODS}.method_get) then
Result := {HTTP_REQUEST_METHODS}.method_get
elseif m.is_case_insensitive_equal ({HTTP_REQUEST_METHODS}.method_post) then
Result := {HTTP_REQUEST_METHODS}.method_post
elseif m.is_case_insensitive_equal ({HTTP_REQUEST_METHODS}.method_head) then
Result := {HTTP_REQUEST_METHODS}.method_head
elseif m.is_case_insensitive_equal ({HTTP_REQUEST_METHODS}.method_trace) then
Result := {HTTP_REQUEST_METHODS}.method_trace
elseif m.is_case_insensitive_equal ({HTTP_REQUEST_METHODS}.method_options) then
Result := {HTTP_REQUEST_METHODS}.method_options
elseif m.is_case_insensitive_equal ({HTTP_REQUEST_METHODS}.method_put) then
Result := {HTTP_REQUEST_METHODS}.method_put
elseif m.is_case_insensitive_equal ({HTTP_REQUEST_METHODS}.method_delete) then
Result := {HTTP_REQUEST_METHODS}.method_delete
elseif m.is_case_insensitive_equal ({HTTP_REQUEST_METHODS}.method_connect) then
Result := {HTTP_REQUEST_METHODS}.method_connect
elseif m.is_case_insensitive_equal ({HTTP_REQUEST_METHODS}.method_patch) then
Result := {HTTP_REQUEST_METHODS}.method_patch
else
Result := m.as_upper
end
end
is_matching_request_methods (a_request_method: READABLE_STRING_8; a_rqst_methods: detachable WSF_ROUTER_METHODS): BOOLEAN
-- `a_request_method' is matching `a_rqst_methods' contents
do
if a_rqst_methods /= Void and then not a_rqst_methods.is_empty then
m := a_request_method
from
i := a_rqst_methods.lower
n := a_rqst_methods.upper
until
i > n or Result
loop
Result := m.same_string (a_rqst_methods [i])
i := i + 1
end
Result := a_rqst_methods.has (a_request_method)
else
Result := True
end
end
formatted_request_methods (rqst_methods: like formatted_request_methods): detachable ARRAY [READABLE_STRING_8]
-- Formatted request methods values
local
i,l,u: INTEGER
do
if rqst_methods /= Void and then not rqst_methods.is_empty then
l := rqst_methods.lower
u := rqst_methods.upper
create Result.make_filled (rqst_methods[l], l, u)
from
i := l + 1
until
i > u
loop
Result[i] := rqst_methods[i].as_string_8.as_upper
i := i + 1
end
end
end
;note
note
copyright: "2011-2012, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[

View File

@@ -0,0 +1,402 @@
note
description: "[
Object that is use in relation with WSF_ROUTER, to precise which request methods is accepted.
For convenience, `make_from_iterable' is available, so that you can use <<"GET", "POST">> for instance
but remember manifest string are evil ...
Since in HTTP you can use your own custom request method, this is not possible to catch any typo
( for instance if you write "POST" instead of "P0ST" this is hard to find the error,
but in one case it uses upper "o" and in the other case this is zero "0"
)
The recommanded way to use is for instance
create {WSF_ROUTER_METHODS}.make_get_post
create methods; methods.enable_get; methods.enable_post
This sounds heavy, but this is much safer.
( note: in addition internally this first checks using reference comparison
and then compare string value, so it brings optimization for accepted request methods.
)
]"
date: "$Date$"
revision: "$Revision$"
class
WSF_ROUTER_METHODS
inherit
ITERABLE [READABLE_STRING_8]
redefine
default_create
end
HTTP_REQUEST_METHODS
redefine
default_create
end
create
default_create,
make,
make_from_iterable,
make_from_string
convert
to_array: {ARRAY [READABLE_STRING_8]},
make_from_iterable ({ITERABLE [READABLE_STRING_8], ITERABLE [STRING_8], ARRAY [READABLE_STRING_8], ARRAY [STRING_8]}),
make_from_string ({READABLE_STRING_8, STRING_8})
feature {NONE} -- Initialization
default_create
do
Precursor
make (1)
end
make (n: INTEGER)
do
create methods.make (n)
end
make_from_iterable (v: ITERABLE [READABLE_STRING_8])
do
make (1)
across
v as vc
loop
smart_add_method (vc.item)
end
end
make_from_string (v: READABLE_STRING_8)
do
make_from_iterable (v.split (','))
end
feature -- Status report
is_locked: BOOLEAN
-- Is Current locked? And then can not be modified?
is_empty: BOOLEAN
do
Result := methods.count = 0
end
has (a_method: READABLE_STRING_8): BOOLEAN
-- Has `a_method' enabled?
require
a_method_is_uppercase: a_method.same_string (a_method.as_upper)
do
-- First look for string object itself,
-- in case `a_method' comes from one of the HTTP_REQUEST_METHODS constants
Result := across methods as c some c.item = a_method end
if not Result then
-- If not found, look for the same string value
Result := across methods as c some c.item.same_string_general (a_method) end
end
end
feature -- Access
new_cursor: ITERATION_CURSOR [READABLE_STRING_8]
-- Fresh cursor associated with current structure
do
Result := methods.new_cursor
end
feature -- Status change
lock
-- Lock current and prevent any change in methods
-- Once it is locked, it is impossible to unlock.
do
is_locked := True
end
feature -- Element change
enable_get
require
is_not_locked: not is_locked
get_disabled: not has (method_get)
do
methods.extend (method_get)
ensure
get_enabled: has (method_get)
end
disable_get
require
is_not_locked: not is_locked
get_enabled: has (method_get)
do
prune_method (method_get)
ensure
get_disabled: not has (method_get)
end
enable_post
require
is_not_locked: not is_locked
post_disabled: not has (method_post)
do
methods.extend (method_post)
ensure
post_enabled: has (method_post)
end
disable_post
require
is_not_locked: not is_locked
post_enabled: has (method_post)
do
prune_method (method_post)
ensure
post_disabled: not has (method_post)
end
enable_put
require
is_not_locked: not is_locked
put_disabled: not has (method_put)
do
methods.extend (method_put)
ensure
put_enabled: has (method_put)
end
disable_put
require
is_not_locked: not is_locked
put_enabled: has (method_put)
do
prune_method (method_put)
ensure
put_disabled: not has (method_put)
end
enable_delete
require
is_not_locked: not is_locked
delete_disabled: not has (method_delete)
do
methods.extend (method_delete)
ensure
delete_enabled: has (method_delete)
end
disable_delete
require
is_not_locked: not is_locked
delete_enabled: has (method_delete)
do
prune_method (method_delete)
ensure
delete_disabled: not has (method_delete)
end
enable_options
require
is_not_locked: not is_locked
options_disabled: not has (method_options)
do
methods.extend (method_options)
ensure
options_enabled: has (method_options)
end
disable_options
require
is_not_locked: not is_locked
options_enabled: has (method_options)
do
prune_method (method_options)
ensure
options_disabled: not has (method_options)
end
enable_head
require
is_not_locked: not is_locked
head_disabled: not has (method_head)
do
methods.extend (method_head)
ensure
head_enabled: has (method_head)
end
disable_head
require
is_not_locked: not is_locked
head_enabled: has (method_head)
do
prune_method (method_head)
ensure
head_disabled: not has (method_head)
end
enable_trace
require
is_not_locked: not is_locked
trace_disabled: not has (method_trace)
do
methods.extend (method_trace)
ensure
trace_enabled: has (method_trace)
end
disable_trace
require
is_not_locked: not is_locked
trace_enabled: has (method_trace)
do
prune_method (method_trace)
ensure
trace_disabled: not has (method_trace)
end
enable_connect
require
is_not_locked: not is_locked
connect_disabled: not has (method_connect)
do
methods.extend (method_connect)
ensure
connect_enabled: has (method_connect)
end
disable_connect
require
is_not_locked: not is_locked
connect_enabled: has (method_connect)
do
prune_method (method_connect)
ensure
connect_disabled: not has (method_connect)
end
enable_patch
require
is_not_locked: not is_locked
patch_disabled: not has (method_patch)
do
methods.extend (method_patch)
ensure
patch_enabled: has (method_patch)
end
disable_patch
require
is_not_locked: not is_locked
patch_enabled: has (method_patch)
do
prune_method (method_patch)
ensure
patch_disabled: not has (method_patch)
end
enable_custom (m: READABLE_STRING_8)
require
is_not_locked: not is_locked
not_blank: not across m as mc some mc.item.is_space end
custom_disabled: not has (m.as_upper)
do
methods.extend (m.as_upper)
ensure
custom_enabled: has (m.as_upper)
end
disable_custom (m: READABLE_STRING_8)
require
is_not_locked: not is_locked
not_blank: not across m as mc some mc.item.is_space end
custom_enabled: has (m.as_upper)
do
prune_method (m.as_upper)
ensure
custom_disabled: not has (m.as_upper)
end
feature -- Access
methods: ARRAYED_LIST [READABLE_STRING_8]
to_array: ARRAY [READABLE_STRING_8]
do
Result := methods.to_array
end
feature {NONE} -- Implementation
smart_add_method (v: READABLE_STRING_8)
do
if v.is_case_insensitive_equal (method_get) then
enable_get
elseif v.is_case_insensitive_equal (method_post) then
enable_post
elseif v.is_case_insensitive_equal (method_put) then
enable_put
elseif v.is_case_insensitive_equal (method_delete) then
enable_delete
elseif v.is_case_insensitive_equal (method_head) then
enable_delete
elseif v.is_case_insensitive_equal (method_options) then
enable_options
elseif v.is_case_insensitive_equal (method_trace) then
enable_trace
elseif v.is_case_insensitive_equal (method_connect) then
enable_connect
elseif v.is_case_insensitive_equal (method_patch) then
enable_patch
else
enable_custom (v)
end
end
add_method (v: READABLE_STRING_8)
require
is_upper_case: v.same_string (v.as_upper)
do
if not is_locked then
methods.extend (v)
end
end
prune_method (v: READABLE_STRING_8)
require
is_upper_case: v.same_string (v.as_upper)
local
m: READABLE_STRING_8
do
if not is_locked then
from
methods.start
until
methods.after
loop
m := methods.item
if m = v or else m.same_string (v) then
methods.remove
else
methods.forth
end
end
end
end
invariant
methods_are_uppercase: across methods as c all c.item.same_string (c.item.as_upper) end
;note
copyright: "2011-2012, Jocelyn Fiat, Javier Velilla, 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

@@ -82,7 +82,8 @@ feature -- Mapping
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_with_request_methods (a_resource: READABLE_STRING_8; h: H;
rqst_methods: detachable WSF_ROUTER_METHODS)
-- Map handler `h' with `a_resource' and `rqst_methods'
do
router.map_with_request_methods (a_resource, h, rqst_methods)
@@ -94,7 +95,7 @@ feature -- Mapping
end
map_agent_with_request_methods (a_resource: READABLE_STRING_8; a_action: PROCEDURE [ANY, TUPLE [ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE]];
rqst_methods: detachable ARRAY [READABLE_STRING_8])
rqst_methods: detachable WSF_ROUTER_METHODS)
do
router.map_agent_with_request_methods (a_resource, a_action, rqst_methods)
end