Merge branch 'master' into v1
This commit is contained in:
@@ -147,7 +147,7 @@ feature -- Status report
|
||||
|
||||
launchable: BOOLEAN
|
||||
do
|
||||
Result := Precursor and port_number >= 0
|
||||
Result := Precursor and 0 <= port_number and port_number <= {NATURAL_16}.max_value
|
||||
end
|
||||
|
||||
;note
|
||||
|
||||
@@ -47,26 +47,22 @@ feature -- Documentation
|
||||
|
||||
feature -- Status
|
||||
|
||||
is_mapping (req: WSF_REQUEST; a_router: WSF_ROUTER): BOOLEAN
|
||||
is_mapping (a_path: READABLE_STRING_8; req: WSF_REQUEST; a_router: WSF_ROUTER): BOOLEAN
|
||||
-- <Precursor>
|
||||
local
|
||||
p: READABLE_STRING_8
|
||||
s: like based_uri
|
||||
do
|
||||
p := path_from_request (req)
|
||||
s := based_uri (uri, a_router)
|
||||
Result := p.starts_with (s)
|
||||
Result := a_path.starts_with (s)
|
||||
end
|
||||
|
||||
try (req: WSF_REQUEST; res: WSF_RESPONSE; sess: WSF_ROUTER_SESSION; a_router: WSF_ROUTER)
|
||||
try (a_path: READABLE_STRING_8; req: WSF_REQUEST; res: WSF_RESPONSE; sess: WSF_ROUTER_SESSION; a_router: WSF_ROUTER)
|
||||
-- <Precursor>
|
||||
local
|
||||
p: READABLE_STRING_8
|
||||
s: like based_uri
|
||||
do
|
||||
p := path_from_request (req)
|
||||
s := based_uri (uri, a_router)
|
||||
if p.starts_with (s) then
|
||||
if a_path.starts_with (s) then
|
||||
sess.set_dispatched_handler (handler)
|
||||
a_router.execute_before (Current)
|
||||
execute_handler (handler, s, req, res)
|
||||
@@ -113,7 +109,7 @@ invariant
|
||||
uri_attached: uri /= Void
|
||||
|
||||
note
|
||||
copyright: "2011-2013, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Eiffel Software and others"
|
||||
copyright: "2011-2015, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Colin Adams, Eiffel Software and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
source: "[
|
||||
Eiffel Software
|
||||
|
||||
@@ -50,13 +50,13 @@ feature -- Documentation
|
||||
|
||||
feature -- Status
|
||||
|
||||
is_mapping (req: WSF_REQUEST; a_router: WSF_ROUTER): BOOLEAN
|
||||
is_mapping (a_path: READABLE_STRING_8; req: WSF_REQUEST; a_router: WSF_ROUTER): BOOLEAN
|
||||
-- <Precursor>
|
||||
local
|
||||
p: READABLE_STRING_8
|
||||
l_uri: like uri
|
||||
do
|
||||
p := path_from_request (req)
|
||||
p := a_path
|
||||
l_uri := based_uri (uri, a_router)
|
||||
if l_uri.ends_with ("/") then
|
||||
if not p.ends_with ("/") then
|
||||
@@ -72,10 +72,10 @@ feature -- Status
|
||||
end
|
||||
end
|
||||
|
||||
try (req: WSF_REQUEST; res: WSF_RESPONSE; sess: WSF_ROUTER_SESSION; a_router: WSF_ROUTER)
|
||||
try (a_path: READABLE_STRING_8; req: WSF_REQUEST; res: WSF_RESPONSE; sess: WSF_ROUTER_SESSION; a_router: WSF_ROUTER)
|
||||
-- <Precursor>
|
||||
do
|
||||
if is_mapping (req, a_router) then
|
||||
if is_mapping (a_path, req, a_router) then
|
||||
sess.set_dispatched_handler (handler)
|
||||
a_router.execute_before (Current)
|
||||
execute_handler (handler, req, res)
|
||||
@@ -106,7 +106,7 @@ feature {NONE} -- Implementation
|
||||
end
|
||||
|
||||
note
|
||||
copyright: "2011-2013, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Eiffel Software and others"
|
||||
copyright: "2011-2015, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Colin Adams, Eiffel Software and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
source: "[
|
||||
Eiffel Software
|
||||
|
||||
@@ -57,36 +57,32 @@ feature -- Documentation
|
||||
|
||||
feature -- Status
|
||||
|
||||
is_mapping (req: WSF_REQUEST; a_router: WSF_ROUTER): BOOLEAN
|
||||
is_mapping (a_path: READABLE_STRING_8; req: WSF_REQUEST; a_router: WSF_ROUTER): BOOLEAN
|
||||
-- <Precursor>
|
||||
local
|
||||
tpl: URI_TEMPLATE
|
||||
p: READABLE_STRING_8
|
||||
do
|
||||
p := path_from_request (req)
|
||||
tpl := based_uri_template (template, a_router)
|
||||
Result := tpl.match (p) /= Void
|
||||
Result := tpl.match (a_path) /= Void
|
||||
end
|
||||
|
||||
try (req: WSF_REQUEST; res: WSF_RESPONSE; sess: WSF_ROUTER_SESSION; a_router: WSF_ROUTER)
|
||||
try (a_path: READABLE_STRING_8; req: WSF_REQUEST; res: WSF_RESPONSE; sess: WSF_ROUTER_SESSION; a_router: WSF_ROUTER)
|
||||
-- <Precursor>
|
||||
local
|
||||
tpl: URI_TEMPLATE
|
||||
p: READABLE_STRING_8
|
||||
new_src: detachable WSF_REQUEST_PATH_PARAMETERS_PROVIDER
|
||||
do
|
||||
p := path_from_request (req)
|
||||
tpl := based_uri_template (template, a_router)
|
||||
if attached tpl.match (p) as tpl_res then
|
||||
if attached tpl.match (a_path) as tpl_res then
|
||||
sess.set_dispatched_handler (handler)
|
||||
a_router.execute_before (Current)
|
||||
--| Applied the context to the request
|
||||
--| in practice, this will fill the {WSF_REQUEST}.path_parameters
|
||||
--| Applied the context to the request
|
||||
--| in practice, this will fill the {WSF_REQUEST}.path_parameters
|
||||
create new_src.make (tpl_res.path_variables.count, tpl_res.path_variables)
|
||||
new_src.apply (req)
|
||||
execute_handler (handler, req, res)
|
||||
--| Revert {WSF_REQUEST}.path_parameters_source to former value
|
||||
--| In case the request object passed by other handler that alters its values.
|
||||
--| Revert {WSF_REQUEST}.path_parameters_source to former value
|
||||
--| In case the request object passed by other handler that alters its values.
|
||||
new_src.revert (req)
|
||||
a_router.execute_after (Current)
|
||||
end
|
||||
@@ -126,7 +122,7 @@ feature {NONE} -- Implementation
|
||||
end
|
||||
|
||||
note
|
||||
copyright: "2011-2013, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Eiffel Software and others"
|
||||
copyright: "2011-2015, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Colin Adams, Eiffel Software and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
source: "[
|
||||
Eiffel Software
|
||||
|
||||
@@ -170,6 +170,20 @@ feature -- Basic operations
|
||||
Result := sess.dispatched_handler
|
||||
end
|
||||
|
||||
feature {WSF_ROUTER_MAPPING} -- Dispatch helper
|
||||
|
||||
path_to_dispatch (req: WSF_REQUEST): READABLE_STRING_8
|
||||
-- Path used by the router, to apply url dispatching of request `req'.
|
||||
-- This can be redefined in descendant, to apply various url mapping, or aliasing
|
||||
-- if needed, or for other purpose.
|
||||
require
|
||||
req_attached: req /= Void
|
||||
do
|
||||
Result := req.percent_encoded_path_info
|
||||
ensure
|
||||
path_from_request_attached: Result /= Void
|
||||
end
|
||||
|
||||
feature {NONE} -- Dispatch implementation
|
||||
|
||||
router_dispatch (req: WSF_REQUEST; res: WSF_RESPONSE; sess: WSF_ROUTER_SESSION)
|
||||
@@ -203,7 +217,9 @@ feature {NONE} -- Dispatch implementation
|
||||
a_request_method_attached: a_request_method /= Void
|
||||
local
|
||||
m: WSF_ROUTER_MAPPING
|
||||
p: like path_to_dispatch
|
||||
do
|
||||
p := path_to_dispatch (req)
|
||||
across
|
||||
mappings as c
|
||||
until
|
||||
@@ -212,7 +228,7 @@ feature {NONE} -- Dispatch implementation
|
||||
if attached c.item as l_info then
|
||||
if is_matching_request_methods (a_request_method, l_info.request_methods) then
|
||||
m := l_info.mapping
|
||||
m.try (req, res, sess, Current)
|
||||
m.try (p, req, res, sess, Current)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -320,16 +336,17 @@ feature -- Status report
|
||||
local
|
||||
m: WSF_ROUTER_MAPPING
|
||||
l_rqsmethods: detachable WSF_REQUEST_METHODS
|
||||
p: like path_to_dispatch
|
||||
do
|
||||
create Result
|
||||
|
||||
p := path_to_dispatch (req)
|
||||
across
|
||||
mappings as c
|
||||
loop
|
||||
m := c.item.mapping
|
||||
if attached {WSF_ROUTING_HANDLER} m.handler as l_routing then
|
||||
l_rqsmethods := l_routing.router.allowed_methods_for_request (req)
|
||||
elseif m.is_mapping (req, Current) then
|
||||
elseif m.is_mapping (p, req, Current) then
|
||||
l_rqsmethods := c.item.request_methods
|
||||
else
|
||||
l_rqsmethods := Void
|
||||
@@ -576,7 +593,7 @@ invariant
|
||||
pre_execution_actions_attached: pre_execution_actions /= Void
|
||||
|
||||
note
|
||||
copyright: "2011-2014, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Colin Adams, Eiffel Software and others"
|
||||
copyright: "2011-2015, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Colin Adams, Eiffel Software and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
source: "[
|
||||
Eiffel Software
|
||||
|
||||
@@ -56,18 +56,20 @@ feature -- Status report
|
||||
|
||||
feature -- Status
|
||||
|
||||
is_mapping (req: WSF_REQUEST; a_router: WSF_ROUTER): BOOLEAN
|
||||
-- Does `Current' accept `req' when using `a_router'?
|
||||
is_mapping (a_path: READABLE_STRING_8; req: WSF_REQUEST; a_router: WSF_ROUTER): BOOLEAN
|
||||
-- Does `Current' accept path `a_path' and request `req' when using `a_router'?
|
||||
require
|
||||
a_path_attached: a_path /= Void
|
||||
req_attached: req /= Void
|
||||
a_router_attached: a_router /= Void
|
||||
deferred
|
||||
end
|
||||
|
||||
try (req: WSF_REQUEST; res: WSF_RESPONSE; sess: WSF_ROUTER_SESSION; a_router: WSF_ROUTER)
|
||||
-- Try using `Current' mapping and if it matches request `req'
|
||||
try (a_path: READABLE_STRING_8; req: WSF_REQUEST; res: WSF_RESPONSE; sess: WSF_ROUTER_SESSION; a_router: WSF_ROUTER)
|
||||
-- Try using `Current' mapping and if it matches path `a_path' and request `req'
|
||||
-- execute associated handler and set this handler in session `sess'.
|
||||
require
|
||||
a_path_attached: a_path /= Void
|
||||
req_attached: req /= Void
|
||||
res_attached: res /= Void
|
||||
sess_attached: sess /= Void
|
||||
@@ -75,20 +77,8 @@ feature -- Status
|
||||
deferred
|
||||
end
|
||||
|
||||
feature -- Helper
|
||||
|
||||
path_from_request (req: WSF_REQUEST): READABLE_STRING_8
|
||||
-- Path used by `Current' to check that mapping matches request `req'
|
||||
require
|
||||
req_attached: req /= Void
|
||||
do
|
||||
Result := req.percent_encoded_path_info
|
||||
ensure
|
||||
path_from_request_attached: Result /= Void
|
||||
end
|
||||
|
||||
note
|
||||
copyright: "2011-2014, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Colin Adams, Eiffel Software and others"
|
||||
copyright: "2011-2015, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Colin Adams, Eiffel Software and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
source: "[
|
||||
Eiffel Software
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
note
|
||||
description: "[
|
||||
This class is used to get a safe temporary file
|
||||
in a specific directory, for an optional prefix, and an optional expected filename.
|
||||
Collection of file system utilities.
|
||||
|
||||
Such as getting safe temporary file in a specific directory,
|
||||
for an optional prefix, and an optional expected filename.
|
||||
]"
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
@@ -11,32 +13,15 @@ class
|
||||
|
||||
feature -- Factory
|
||||
|
||||
new_temporary_file (d: DIRECTORY; a_prefix: detachable READABLE_STRING_GENERAL; a_name: detachable READABLE_STRING_GENERAL): detachable G
|
||||
-- New temporary file open for writing inside directory `d', with prefix `a_prefix' is set, and based on name `a_name' is set.
|
||||
-- If it is unable to create such file opened for writing, then return Void.
|
||||
require
|
||||
d_valid: d.exists and then d.is_writable
|
||||
new_file (p: PATH): detachable G
|
||||
-- New temporary file open for writing at location `p' or appended with integer suffix if already exists.
|
||||
local
|
||||
f: G
|
||||
fn: PATH
|
||||
bn, tmp: STRING_32
|
||||
dn: PATH
|
||||
bn: STRING_32
|
||||
n: INTEGER
|
||||
do
|
||||
from
|
||||
if a_prefix /= Void then
|
||||
create tmp.make_from_string_general (a_prefix)
|
||||
else
|
||||
create tmp.make_from_string_general ("tmp")
|
||||
end
|
||||
dn := d.path
|
||||
if a_name /= Void then
|
||||
tmp.append_character ('-')
|
||||
tmp.append_string_general (safe_filename (a_name))
|
||||
end
|
||||
|
||||
fn := dn.extended (tmp)
|
||||
create f.make_with_path (fn)
|
||||
create f.make_with_path (p)
|
||||
Result := new_file_opened_for_writing (f)
|
||||
n := 0
|
||||
until
|
||||
@@ -44,17 +29,43 @@ feature -- Factory
|
||||
or else n > 1_000
|
||||
loop
|
||||
n := n + 1
|
||||
create bn.make_from_string (tmp)
|
||||
create bn.make (2 + n // 10)
|
||||
bn.append_character ('-')
|
||||
bn.append_integer (n)
|
||||
fn := dn.extended (bn)
|
||||
f.make_with_path (fn)
|
||||
f.make_with_path (p.appended (bn))
|
||||
Result := new_file_opened_for_writing (f)
|
||||
end
|
||||
ensure
|
||||
result_opened_for_writing_if_set: Result /= Void implies Result.is_open_write
|
||||
end
|
||||
|
||||
new_temporary_file (d: DIRECTORY; a_prefix: detachable READABLE_STRING_GENERAL; a_name: detachable READABLE_STRING_GENERAL): detachable G
|
||||
-- New temporary file open for writing inside directory `d', with prefix `a_prefix' is set, and based on name `a_name' is set.
|
||||
-- If it is unable to create such file opened for writing, then return Void.
|
||||
require
|
||||
d_valid: d.exists and then d.is_writable
|
||||
local
|
||||
fn: PATH
|
||||
tmp: STRING_32
|
||||
dn: PATH
|
||||
do
|
||||
if a_prefix /= Void then
|
||||
create tmp.make_from_string_general (a_prefix)
|
||||
else
|
||||
create tmp.make_from_string_general ("tmp")
|
||||
end
|
||||
dn := d.path
|
||||
if a_name /= Void then
|
||||
tmp.append_character ('-')
|
||||
tmp.append_string_general (safe_filename (a_name))
|
||||
end
|
||||
|
||||
fn := dn.extended (tmp)
|
||||
Result := new_file (fn)
|
||||
ensure
|
||||
result_opened_for_writing_if_set: Result /= Void implies Result.is_open_write
|
||||
end
|
||||
|
||||
safe_filename (fn: READABLE_STRING_GENERAL): STRING
|
||||
-- Safe filename that avoid impossible filename, or dangerous one.
|
||||
local
|
||||
@@ -162,7 +173,7 @@ feature {NONE} -- Implementation
|
||||
end
|
||||
|
||||
note
|
||||
copyright: "2011-2014, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Colin Adams, Eiffel Software and others"
|
||||
copyright: "2011-2015, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Colin Adams, Eiffel Software and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
source: "[
|
||||
Eiffel Software
|
||||
|
||||
Reference in New Issue
Block a user