Further changes in response to review comments by Jocelyn
This commit is contained in:
@@ -0,0 +1,27 @@
|
|||||||
|
note
|
||||||
|
description: "Summary description for {WSF_URI_TEMPLATE_ROUTED_SERVICE}."
|
||||||
|
author: ""
|
||||||
|
date: "$Date$"
|
||||||
|
revision: "$Revision$"
|
||||||
|
|
||||||
|
deferred class
|
||||||
|
WSF_URI_TEMPLATE_ROUTED_SERVICE
|
||||||
|
|
||||||
|
obsolete "Inherit from WSF_ROUTED_SERVICE and WSF_URI_ROUTER_HELPER [2013-mar-19]"
|
||||||
|
|
||||||
|
inherit
|
||||||
|
WSF_ROUTED_SERVICE
|
||||||
|
|
||||||
|
WSF_URI_TEMPLATE_ROUTER_HELPER
|
||||||
|
|
||||||
|
note
|
||||||
|
copyright: "2011-2013, Jocelyn Fiat, Javier Velilla, Olivier Ligot, 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
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
note
|
||||||
|
description: "Summary description for {WSF_URI_TEMPLATE_ROUTER_HELPER}."
|
||||||
|
author: ""
|
||||||
|
date: "$Date$"
|
||||||
|
revision: "$Revision$"
|
||||||
|
|
||||||
|
deferred class
|
||||||
|
WSF_URI_TEMPLATE_ROUTER_HELPER
|
||||||
|
|
||||||
|
obsolete "Use class WSF_URI_TEMPLATE_HELPER_FOR_ROUTED_SERVICE in conjunction with WSF_ROUTED_SKELETON_SERVICE"
|
||||||
|
|
||||||
|
feature -- Access
|
||||||
|
|
||||||
|
router: WSF_ROUTER
|
||||||
|
deferred
|
||||||
|
end
|
||||||
|
|
||||||
|
feature -- Mapping helper: uri
|
||||||
|
|
||||||
|
map_uri_template (a_tpl: STRING; h: WSF_URI_TEMPLATE_HANDLER)
|
||||||
|
-- Map `h' as handler for `a_tpl'
|
||||||
|
require
|
||||||
|
a_tpl_attached: a_tpl /= Void
|
||||||
|
h_attached: h /= Void
|
||||||
|
do
|
||||||
|
map_uri_template_with_request_methods (a_tpl, h, Void)
|
||||||
|
end
|
||||||
|
|
||||||
|
map_uri_template_with_request_methods (a_tpl: READABLE_STRING_8; h: WSF_URI_TEMPLATE_HANDLER; rqst_methods: detachable WSF_REQUEST_METHODS)
|
||||||
|
-- Map `h' as handler for `a_tpl' for request methods `rqst_methods'.
|
||||||
|
require
|
||||||
|
a_tpl_attached: a_tpl /= Void
|
||||||
|
h_attached: h /= Void
|
||||||
|
do
|
||||||
|
router.map_with_request_methods (create {WSF_URI_TEMPLATE_MAPPING}.make (a_tpl, h), rqst_methods)
|
||||||
|
end
|
||||||
|
|
||||||
|
feature -- Mapping helper: uri agent
|
||||||
|
|
||||||
|
map_uri_template_agent (a_tpl: READABLE_STRING_8; proc: PROCEDURE [ANY, TUPLE [req: WSF_REQUEST; res: WSF_RESPONSE]])
|
||||||
|
-- Map `proc' as handler for `a_tpl'
|
||||||
|
require
|
||||||
|
a_tpl_attached: a_tpl /= Void
|
||||||
|
proc_attached: proc /= Void
|
||||||
|
do
|
||||||
|
map_uri_template_agent_with_request_methods (a_tpl, proc, Void)
|
||||||
|
end
|
||||||
|
|
||||||
|
map_uri_template_agent_with_request_methods (a_tpl: READABLE_STRING_8; proc: PROCEDURE [ANY, TUPLE [req: WSF_REQUEST; res: WSF_RESPONSE]]; rqst_methods: detachable WSF_REQUEST_METHODS)
|
||||||
|
-- Map `proc' as handler for `a_tpl' for request methods `rqst_methods'.
|
||||||
|
require
|
||||||
|
a_tpl_attached: a_tpl /= Void
|
||||||
|
proc_attached: proc /= Void
|
||||||
|
do
|
||||||
|
map_uri_template_with_request_methods (a_tpl, create {WSF_URI_TEMPLATE_AGENT_HANDLER}.make (proc), rqst_methods)
|
||||||
|
end
|
||||||
|
|
||||||
|
note
|
||||||
|
copyright: "2011-2013, Jocelyn Fiat, Javier Velilla, Olivier Ligot, 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
|
||||||
@@ -22,6 +22,8 @@ feature -- Execution
|
|||||||
execute (req: WSF_REQUEST; res: WSF_RESPONSE)
|
execute (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||||
-- If the service is available, and request URI is not too long, dispatch the request
|
-- If the service is available, and request URI is not too long, dispatch the request
|
||||||
-- and if handler is not found, execute the default procedure `execute_default'.
|
-- and if handler is not found, execute the default procedure `execute_default'.
|
||||||
|
local
|
||||||
|
l_sess: WSF_ROUTER_SESSION
|
||||||
do
|
do
|
||||||
--| When we reach here, the request has already passed check for 400 (Bad request),
|
--| When we reach here, the request has already passed check for 400 (Bad request),
|
||||||
--| which is implemented in WSF_REQUEST.make_from_wgi (when it calls `analyze').
|
--| which is implemented in WSF_REQUEST.make_from_wgi (when it calls `analyze').
|
||||||
@@ -34,10 +36,12 @@ feature -- Execution
|
|||||||
elseif req.is_request_method ({HTTP_REQUEST_METHODS}.method_options) and then
|
elseif req.is_request_method ({HTTP_REQUEST_METHODS}.method_options) and then
|
||||||
req.request_uri.same_string ("*") then
|
req.request_uri.same_string ("*") then
|
||||||
handle_server_options (req, res)
|
handle_server_options (req, res)
|
||||||
elseif attached router.dispatch_and_return_handler (req, res) as p then
|
|
||||||
-- executed
|
|
||||||
else
|
else
|
||||||
execute_default (req, res)
|
create l_sess
|
||||||
|
router.dispatch (req, res, l_sess)
|
||||||
|
if not l_sess.dispatched then
|
||||||
|
execute_default (req, res)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -180,7 +184,7 @@ feature {NONE} -- Implementation
|
|||||||
|
|
||||||
frozen handle_system_options_forbidden (req: WSF_REQUEST; res: WSF_RESPONSE)
|
frozen handle_system_options_forbidden (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||||
-- Write a 403 Forbidden or a 404 Not found response into `res'.
|
-- Write a 403 Forbidden or a 404 Not found response into `res'.
|
||||||
require
|
require
|
||||||
req_attached: req /= Void
|
req_attached: req /= Void
|
||||||
res_attached: res /= Void
|
res_attached: res /= Void
|
||||||
method_is_options: req.is_request_method ({HTTP_REQUEST_METHODS}.method_options)
|
method_is_options: req.is_request_method ({HTTP_REQUEST_METHODS}.method_options)
|
||||||
@@ -217,7 +221,7 @@ feature {NONE} -- Implementation
|
|||||||
handle_system_options (req: WSF_REQUEST; res: WSF_RESPONSE)
|
handle_system_options (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||||
-- Write response to OPTIONS * into `res'.
|
-- Write response to OPTIONS * into `res'.
|
||||||
-- This may be redefined by the user, but normally this will not be necessary.
|
-- This may be redefined by the user, but normally this will not be necessary.
|
||||||
require
|
require
|
||||||
req_attached: req /= Void
|
req_attached: req /= Void
|
||||||
res_attached: res /= Void
|
res_attached: res /= Void
|
||||||
method_is_options: req.is_request_method ({HTTP_REQUEST_METHODS}.method_options)
|
method_is_options: req.is_request_method ({HTTP_REQUEST_METHODS}.method_options)
|
||||||
|
|||||||
@@ -82,17 +82,18 @@ feature {WSF_RESPONSE} -- Output
|
|||||||
l_text: detachable READABLE_STRING_GENERAL
|
l_text: detachable READABLE_STRING_GENERAL
|
||||||
l_loc: detachable READABLE_STRING_8
|
l_loc: detachable READABLE_STRING_8
|
||||||
h: like header
|
h: like header
|
||||||
l_recognized: BOOLEAN
|
--l_recognized: BOOLEAN
|
||||||
l_messages: HTTP_STATUS_CODE_MESSAGES
|
l_messages: HTTP_STATUS_CODE_MESSAGES
|
||||||
do
|
do
|
||||||
create l_messages
|
create l_messages
|
||||||
h := header
|
h := header
|
||||||
l_recognized := recognized_methods.has (request.request_method.as_upper)
|
-- To be considered later
|
||||||
if l_recognized then
|
--l_recognized := recognized_methods.has (request.request_method.as_upper)
|
||||||
res.set_status_code (l_messages.method_not_allowed)
|
--if l_recognized then
|
||||||
else
|
res.set_status_code (l_messages.method_not_allowed)
|
||||||
res.set_status_code (l_messages.not_implemented)
|
--else
|
||||||
end
|
-- res.set_status_code (l_messages.not_implemented)
|
||||||
|
--end
|
||||||
|
|
||||||
if attached suggested_methods as lst and then not lst.is_empty then
|
if attached suggested_methods as lst and then not lst.is_empty then
|
||||||
h.put_allow (lst)
|
h.put_allow (lst)
|
||||||
@@ -109,7 +110,7 @@ feature {WSF_RESPONSE} -- Output
|
|||||||
s := "Bug in server"
|
s := "Bug in server"
|
||||||
end
|
end
|
||||||
|
|
||||||
l_html_error_code_text := html_error_code_text (l_messages, l_recognized)
|
l_html_error_code_text := html_error_code_text (l_messages, True)
|
||||||
|
|
||||||
if request.is_content_type_accepted ({HTTP_MIME_TYPES}.text_html) then
|
if request.is_content_type_accepted ({HTTP_MIME_TYPES}.text_html) then
|
||||||
s := "<html lang=%"en%"><head>"
|
s := "<html lang=%"en%"><head>"
|
||||||
@@ -262,23 +263,24 @@ feature {WSF_RESPONSE} -- Output
|
|||||||
|
|
||||||
feature {NONE} -- Implementation
|
feature {NONE} -- Implementation
|
||||||
|
|
||||||
recognized_methods: WSF_REQUEST_METHODS
|
-- To be discussed later...
|
||||||
|
--recognized_methods: WSF_REQUEST_METHODS
|
||||||
-- All methods defined in HTTP/1.1 specification
|
-- All methods defined in HTTP/1.1 specification
|
||||||
--| Should this include CONNECT? It probably shouldn't be recognized by an origin server,
|
--| Should this include CONNECT? It probably shouldn't be recognized by an origin server,
|
||||||
--| We will need a way to extend this for additional methods that the server implements. E.g. PATCH.
|
--| We will need a way to extend this for additional methods that the server implements. E.g. PATCH.
|
||||||
do
|
-- do
|
||||||
create Result.make_from_iterable (<<
|
-- create Result.make_from_iterable (<<
|
||||||
{HTTP_REQUEST_METHODS}.method_head,
|
-- {HTTP_REQUEST_METHODS}.method_head,
|
||||||
{HTTP_REQUEST_METHODS}.method_get,
|
-- {HTTP_REQUEST_METHODS}.method_get,
|
||||||
{HTTP_REQUEST_METHODS}.method_trace,
|
-- {HTTP_REQUEST_METHODS}.method_trace,
|
||||||
{HTTP_REQUEST_METHODS}.method_options,
|
-- {HTTP_REQUEST_METHODS}.method_options,
|
||||||
{HTTP_REQUEST_METHODS}.method_post,
|
-- {HTTP_REQUEST_METHODS}.method_post,
|
||||||
{HTTP_REQUEST_METHODS}.method_put,
|
-- {HTTP_REQUEST_METHODS}.method_put,
|
||||||
{HTTP_REQUEST_METHODS}.method_delete
|
-- {HTTP_REQUEST_METHODS}.method_delete
|
||||||
>>)
|
-- >>)
|
||||||
ensure
|
-- ensure
|
||||||
recognized_methods_not_void: Result /= Void
|
-- recognized_methods_not_void: Result /= Void
|
||||||
end
|
-- end
|
||||||
|
|
||||||
html_error_code_text (a_messages: HTTP_STATUS_CODE_MESSAGES; a_recognized: BOOLEAN): READABLE_STRING_8
|
html_error_code_text (a_messages: HTTP_STATUS_CODE_MESSAGES; a_recognized: BOOLEAN): READABLE_STRING_8
|
||||||
-- Message for including in HTML error text according to `a_recognized'
|
-- Message for including in HTML error text according to `a_recognized'
|
||||||
|
|||||||
Reference in New Issue
Block a user