Breaking changes:
added `a_request_methods' argument to WSF_ROUTER_SELF_DOCUMENTATION_HANDLER.mapping_documentation added similar argument to WSF_ROUTER_SELF_DOCUMENTATION_ROUTER_MAPPING.documentation Renamed WSF_ROUTER_METHODS as WSF_REQUEST_METHODS Enhanced WSF_REQUEST_METHODS with new has_... function Added WSF_ROUTER_VISITOR and WSF_ROUTER_ITERATOR that may be useful to iterate inside the router. we may improve the implementation of the router using those visitors in the future. Improved the WSF_DEFAULT_RESPONSE to embedded suggested items (typically based on pseudo self documented router)
This commit is contained in:
@@ -24,15 +24,13 @@ note
|
||||
class
|
||||
WSF_ROUTER_METHODS
|
||||
|
||||
inherit
|
||||
ITERABLE [READABLE_STRING_8]
|
||||
redefine
|
||||
default_create
|
||||
end
|
||||
obsolete
|
||||
"Use WSF_REQUEST_METHODS"
|
||||
|
||||
HTTP_REQUEST_METHODS
|
||||
inherit
|
||||
WSF_REQUEST_METHODS
|
||||
redefine
|
||||
default_create
|
||||
plus
|
||||
end
|
||||
|
||||
create
|
||||
@@ -46,364 +44,21 @@ convert
|
||||
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)
|
||||
add_methods (v)
|
||||
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: INDEXABLE_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 -- Basic operations
|
||||
|
||||
add alias "+" (a_other: WSF_ROUTER_METHODS): WSF_ROUTER_METHODS
|
||||
add (a_other: like plus): like plus
|
||||
obsolete "Use `plus' or `alias +'"
|
||||
do
|
||||
Result := plus (a_other)
|
||||
end
|
||||
|
||||
plus alias "+" (a_other: WSF_ROUTER_METHODS): WSF_ROUTER_METHODS
|
||||
-- Merge Current and a_other into Result
|
||||
require
|
||||
a_other_not_void: a_other /= Void
|
||||
do
|
||||
create Result.make_from_iterable (Current)
|
||||
Result.add_methods (a_other)
|
||||
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 {WSF_ROUTER_METHODS} -- Implementation
|
||||
|
||||
add_methods (lst: ITERABLE [READABLE_STRING_8])
|
||||
-- Enable methods from `lst'
|
||||
do
|
||||
if not is_locked then
|
||||
across
|
||||
lst as c
|
||||
loop
|
||||
add_method_using_constant (c.item)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
add_method_using_constant (v: READABLE_STRING_8)
|
||||
-- Add method `v' using method_* constant
|
||||
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_head
|
||||
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
|
||||
ensure
|
||||
method_set: has (v.as_upper)
|
||||
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, Olivier Ligot, Eiffel Software and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
|
||||
Reference in New Issue
Block a user