Skip to content

Commit 7fbfda3

Browse files
committed
Refactored wsf router dispatching implementation.
Now the path to take into account during dispatching is computed once in WSF_ROUTER.path_to_dispatch (req: WSF_REQUEST): READABLE_STRING_8 And this function could be redefined in descendant of WSF_ROUTER.
1 parent 9e46768 commit 7fbfda3

File tree

5 files changed

+47
-48
lines changed

5 files changed

+47
-48
lines changed

library/server/wsf/router/support/starts_with/wsf_starts_with_mapping_i.e

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,26 +47,22 @@ feature -- Documentation
4747

4848
feature -- Status
4949

50-
is_mapping (req: WSF_REQUEST; a_router: WSF_ROUTER): BOOLEAN
50+
is_mapping (a_path: READABLE_STRING_8; req: WSF_REQUEST; a_router: WSF_ROUTER): BOOLEAN
5151
-- <Precursor>
5252
local
53-
p: READABLE_STRING_8
5453
s: like based_uri
5554
do
56-
p := path_from_request (req)
5755
s := based_uri (uri, a_router)
58-
Result := p.starts_with (s)
56+
Result := a_path.starts_with (s)
5957
end
6058

61-
try (req: WSF_REQUEST; res: WSF_RESPONSE; sess: WSF_ROUTER_SESSION; a_router: WSF_ROUTER)
59+
try (a_path: READABLE_STRING_8; req: WSF_REQUEST; res: WSF_RESPONSE; sess: WSF_ROUTER_SESSION; a_router: WSF_ROUTER)
6260
-- <Precursor>
6361
local
64-
p: READABLE_STRING_8
6562
s: like based_uri
6663
do
67-
p := path_from_request (req)
6864
s := based_uri (uri, a_router)
69-
if p.starts_with (s) then
65+
if a_path.starts_with (s) then
7066
sess.set_dispatched_handler (handler)
7167
a_router.execute_before (Current)
7268
execute_handler (handler, s, req, res)
@@ -113,7 +109,7 @@ invariant
113109
uri_attached: uri /= Void
114110

115111
note
116-
copyright: "2011-2013, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Eiffel Software and others"
112+
copyright: "2011-2015, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Colin Adams, Eiffel Software and others"
117113
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
118114
source: "[
119115
Eiffel Software

library/server/wsf/router/support/uri/wsf_uri_mapping_i.e

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ feature -- Documentation
5050

5151
feature -- Status
5252

53-
is_mapping (req: WSF_REQUEST; a_router: WSF_ROUTER): BOOLEAN
53+
is_mapping (a_path: READABLE_STRING_8; req: WSF_REQUEST; a_router: WSF_ROUTER): BOOLEAN
5454
-- <Precursor>
5555
local
5656
p: READABLE_STRING_8
5757
l_uri: like uri
5858
do
59-
p := path_from_request (req)
59+
p := a_path
6060
l_uri := based_uri (uri, a_router)
6161
if l_uri.ends_with ("/") then
6262
if not p.ends_with ("/") then
@@ -72,10 +72,10 @@ feature -- Status
7272
end
7373
end
7474

75-
try (req: WSF_REQUEST; res: WSF_RESPONSE; sess: WSF_ROUTER_SESSION; a_router: WSF_ROUTER)
75+
try (a_path: READABLE_STRING_8; req: WSF_REQUEST; res: WSF_RESPONSE; sess: WSF_ROUTER_SESSION; a_router: WSF_ROUTER)
7676
-- <Precursor>
7777
do
78-
if is_mapping (req, a_router) then
78+
if is_mapping (a_path, req, a_router) then
7979
sess.set_dispatched_handler (handler)
8080
a_router.execute_before (Current)
8181
execute_handler (handler, req, res)
@@ -106,7 +106,7 @@ feature {NONE} -- Implementation
106106
end
107107

108108
note
109-
copyright: "2011-2013, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Eiffel Software and others"
109+
copyright: "2011-2015, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Colin Adams, Eiffel Software and others"
110110
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
111111
source: "[
112112
Eiffel Software

library/server/wsf/router/support/uri_template/wsf_uri_template_mapping_i.e

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -57,36 +57,32 @@ feature -- Documentation
5757

5858
feature -- Status
5959

60-
is_mapping (req: WSF_REQUEST; a_router: WSF_ROUTER): BOOLEAN
60+
is_mapping (a_path: READABLE_STRING_8; req: WSF_REQUEST; a_router: WSF_ROUTER): BOOLEAN
6161
-- <Precursor>
6262
local
6363
tpl: URI_TEMPLATE
64-
p: READABLE_STRING_8
6564
do
66-
p := path_from_request (req)
6765
tpl := based_uri_template (template, a_router)
68-
Result := tpl.match (p) /= Void
66+
Result := tpl.match (a_path) /= Void
6967
end
7068

71-
try (req: WSF_REQUEST; res: WSF_RESPONSE; sess: WSF_ROUTER_SESSION; a_router: WSF_ROUTER)
69+
try (a_path: READABLE_STRING_8; req: WSF_REQUEST; res: WSF_RESPONSE; sess: WSF_ROUTER_SESSION; a_router: WSF_ROUTER)
7270
-- <Precursor>
7371
local
7472
tpl: URI_TEMPLATE
75-
p: READABLE_STRING_8
7673
new_src: detachable WSF_REQUEST_PATH_PARAMETERS_PROVIDER
7774
do
78-
p := path_from_request (req)
7975
tpl := based_uri_template (template, a_router)
80-
if attached tpl.match (p) as tpl_res then
76+
if attached tpl.match (a_path) as tpl_res then
8177
sess.set_dispatched_handler (handler)
8278
a_router.execute_before (Current)
83-
--| Applied the context to the request
84-
--| in practice, this will fill the {WSF_REQUEST}.path_parameters
79+
--| Applied the context to the request
80+
--| in practice, this will fill the {WSF_REQUEST}.path_parameters
8581
create new_src.make (tpl_res.path_variables.count, tpl_res.path_variables)
8682
new_src.apply (req)
8783
execute_handler (handler, req, res)
88-
--| Revert {WSF_REQUEST}.path_parameters_source to former value
89-
--| In case the request object passed by other handler that alters its values.
84+
--| Revert {WSF_REQUEST}.path_parameters_source to former value
85+
--| In case the request object passed by other handler that alters its values.
9086
new_src.revert (req)
9187
a_router.execute_after (Current)
9288
end
@@ -126,7 +122,7 @@ feature {NONE} -- Implementation
126122
end
127123

128124
note
129-
copyright: "2011-2013, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Eiffel Software and others"
125+
copyright: "2011-2015, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Colin Adams, Eiffel Software and others"
130126
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
131127
source: "[
132128
Eiffel Software

library/server/wsf/router/wsf_router.e

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,20 @@ feature -- Basic operations
170170
Result := sess.dispatched_handler
171171
end
172172

173+
feature {WSF_ROUTER_MAPPING} -- Dispatch helper
174+
175+
path_to_dispatch (req: WSF_REQUEST): READABLE_STRING_8
176+
-- Path used by the router, to apply url dispatching of request `req'.
177+
-- This can be redefined in descendant, to apply various url mapping, or aliasing
178+
-- if needed, or for other purpose.
179+
require
180+
req_attached: req /= Void
181+
do
182+
Result := req.percent_encoded_path_info
183+
ensure
184+
path_from_request_attached: Result /= Void
185+
end
186+
173187
feature {NONE} -- Dispatch implementation
174188

175189
router_dispatch (req: WSF_REQUEST; res: WSF_RESPONSE; sess: WSF_ROUTER_SESSION)
@@ -203,7 +217,9 @@ feature {NONE} -- Dispatch implementation
203217
a_request_method_attached: a_request_method /= Void
204218
local
205219
m: WSF_ROUTER_MAPPING
220+
p: like path_to_dispatch
206221
do
222+
p := path_to_dispatch (req)
207223
across
208224
mappings as c
209225
until
@@ -212,7 +228,7 @@ feature {NONE} -- Dispatch implementation
212228
if attached c.item as l_info then
213229
if is_matching_request_methods (a_request_method, l_info.request_methods) then
214230
m := l_info.mapping
215-
m.try (req, res, sess, Current)
231+
m.try (p, req, res, sess, Current)
216232
end
217233
end
218234
end
@@ -320,16 +336,17 @@ feature -- Status report
320336
local
321337
m: WSF_ROUTER_MAPPING
322338
l_rqsmethods: detachable WSF_REQUEST_METHODS
339+
p: like path_to_dispatch
323340
do
324341
create Result
325-
342+
p := path_to_dispatch (req)
326343
across
327344
mappings as c
328345
loop
329346
m := c.item.mapping
330347
if attached {WSF_ROUTING_HANDLER} m.handler as l_routing then
331348
l_rqsmethods := l_routing.router.allowed_methods_for_request (req)
332-
elseif m.is_mapping (req, Current) then
349+
elseif m.is_mapping (p, req, Current) then
333350
l_rqsmethods := c.item.request_methods
334351
else
335352
l_rqsmethods := Void
@@ -576,7 +593,7 @@ invariant
576593
pre_execution_actions_attached: pre_execution_actions /= Void
577594

578595
note
579-
copyright: "2011-2014, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Colin Adams, Eiffel Software and others"
596+
copyright: "2011-2015, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Colin Adams, Eiffel Software and others"
580597
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
581598
source: "[
582599
Eiffel Software

library/server/wsf/router/wsf_router_mapping.e

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -56,39 +56,29 @@ feature -- Status report
5656

5757
feature -- Status
5858

59-
is_mapping (req: WSF_REQUEST; a_router: WSF_ROUTER): BOOLEAN
60-
-- Does `Current' accept `req' when using `a_router'?
59+
is_mapping (a_path: READABLE_STRING_8; req: WSF_REQUEST; a_router: WSF_ROUTER): BOOLEAN
60+
-- Does `Current' accept path `a_path' and request `req' when using `a_router'?
6161
require
62+
a_path_attached: a_path /= Void
6263
req_attached: req /= Void
6364
a_router_attached: a_router /= Void
6465
deferred
6566
end
6667

67-
try (req: WSF_REQUEST; res: WSF_RESPONSE; sess: WSF_ROUTER_SESSION; a_router: WSF_ROUTER)
68-
-- Try using `Current' mapping and if it matches request `req'
68+
try (a_path: READABLE_STRING_8; req: WSF_REQUEST; res: WSF_RESPONSE; sess: WSF_ROUTER_SESSION; a_router: WSF_ROUTER)
69+
-- Try using `Current' mapping and if it matches path `a_path' and request `req'
6970
-- execute associated handler and set this handler in session `sess'.
7071
require
72+
a_path_attached: a_path /= Void
7173
req_attached: req /= Void
7274
res_attached: res /= Void
7375
sess_attached: sess /= Void
7476
a_router_attached: a_router /= Void
7577
deferred
7678
end
7779

78-
feature -- Helper
79-
80-
path_from_request (req: WSF_REQUEST): READABLE_STRING_8
81-
-- Path used by `Current' to check that mapping matches request `req'
82-
require
83-
req_attached: req /= Void
84-
do
85-
Result := req.percent_encoded_path_info
86-
ensure
87-
path_from_request_attached: Result /= Void
88-
end
89-
9080
note
91-
copyright: "2011-2014, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Colin Adams, Eiffel Software and others"
81+
copyright: "2011-2015, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Colin Adams, Eiffel Software and others"
9282
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
9383
source: "[
9484
Eiffel Software

0 commit comments

Comments
 (0)