diff --git a/library/server/request/rest/src/contrib/doc/rest_api_documentation.e b/library/server/request/rest/src/contrib/doc/rest_api_documentation.e
index 276b2653..939e0c27 100644
--- a/library/server/request/rest/src/contrib/doc/rest_api_documentation.e
+++ b/library/server/request/rest/src/contrib/doc/rest_api_documentation.e
@@ -20,7 +20,6 @@ feature {NONE} -- Initialization
router := a_router
base_doc_url := a_base_doc_url
description := "Technical documention for the API"
- initialize
end
feature {NONE} -- Access: Implementation
@@ -31,7 +30,9 @@ feature {NONE} -- Access: Implementation
feature -- Access
- authentication_required: BOOLEAN = False
+ authentication_required (req: WGI_REQUEST): BOOLEAN
+ do
+ end
feature -- Execution
@@ -187,7 +188,7 @@ feature -- Execution
end
s.append_string ("")
end
- s.append_string ("
Authentication required: " + rq.authentication_required.out + "
")
+ s.append_string ("Authentication required: " + rq.authentication_required (req).out + "
")
if attached {REST_REQUEST_URI_TEMPLATE_ROUTER_I [REST_REQUEST_HANDLER [REST_REQUEST_URI_TEMPLATE_HANDLER_CONTEXT], REST_REQUEST_URI_TEMPLATE_HANDLER_CONTEXT]} router as l_uri_template_router then
create l_uri_tpl.make (a_resource)
if attached l_uri_tpl.query_variable_names as l_query_variable_names and then not l_query_variable_names.is_empty then
diff --git a/library/server/request/rest/src/rest_request_agent_handler.e b/library/server/request/rest/src/rest_request_agent_handler.e
index ba85571e..eca7824a 100644
--- a/library/server/request/rest/src/rest_request_agent_handler.e
+++ b/library/server/request/rest/src/rest_request_agent_handler.e
@@ -22,26 +22,33 @@ create
feature -- status
- authentication_required: BOOLEAN
+ authentication_required (req: WGI_REQUEST): BOOLEAN
+ do
+ Result := internal_authentication_required
+ end
feature -- Element change
set_authentication_required (b: like authentication_required)
do
- authentication_required := b
+ internal_authentication_required := b
end
+feature {NONE} -- Implementation
+
+ internal_authentication_required: BOOLEAN
+
feature -- Execution
- execute (a_hdl_context: C; req: WGI_REQUEST; res: WGI_RESPONSE_BUFFER)
+ execute (ctx: C; req: WGI_REQUEST; res: WGI_RESPONSE_BUFFER)
do
- Precursor {REST_REQUEST_HANDLER} (a_hdl_context, req, res)
+ Precursor {REST_REQUEST_HANDLER} (ctx, req, res)
end
--- execute_application (ctx: REST_REQUEST_HANDLER_CONTEXT; req: WGI_REQUEST; res: WGI_RESPONSE_BUFFER)
--- do
--- action.call ([ctx, req, res])
--- end
+ execute_application (ctx: C; req: WGI_REQUEST; res: WGI_RESPONSE_BUFFER)
+ do
+ check should_not_occur: False end
+ end
;note
copyright: "Copyright (c) 1984-2011, Eiffel Software and others"
diff --git a/library/server/request/rest/src/rest_request_handler.e b/library/server/request/rest/src/rest_request_handler.e
index 8e9810a8..6f3c8bc6 100644
--- a/library/server/request/rest/src/rest_request_handler.e
+++ b/library/server/request/rest/src/rest_request_handler.e
@@ -15,32 +15,74 @@ inherit
feature -- Access
- authentication_required: BOOLEAN
+ authentication_required (req: WGI_REQUEST): BOOLEAN
-- Is authentication required
-- might depend on the request environment
-- or the associated resources
deferred
end
+ description: detachable STRING
+ -- Optional descriptiong
+
+feature -- Element change
+
+ set_description (s: like description)
+ -- Set `description' to `s'
+ do
+ description := s
+ end
+
feature -- Execution
- execute (a_hdl_context: C; req: WGI_REQUEST; res: WGI_RESPONSE_BUFFER)
+ execute (ctx: C; req: WGI_REQUEST; res: WGI_RESPONSE_BUFFER)
-- Execute request handler
+ local
+ rescued: BOOLEAN
do
- if authentication_required and then not a_hdl_context.authenticated then
- execute_unauthorized (a_hdl_context, req, res)
+ if not rescued then
+ if request_method_name_supported (req.request_method) then
+ if authentication_required (req) and then not ctx.authenticated then
+ execute_unauthorized (ctx, req, res)
+ else
+ pre_execute (ctx, req, res)
+ execute_application (ctx, req, res)
+ post_execute (ctx, req, res)
+ end
+ else
+ execute_request_method_not_allowed (req, res, supported_request_method_names)
+ end
else
- Precursor (a_hdl_context, req, res)
+ rescue_execute (ctx, req, res)
end
+ rescue
+ rescued := True
+ retry
end
- execute_unauthorized (a_hdl_context: C; req: WGI_REQUEST; res: WGI_RESPONSE_BUFFER)
+ execute_application (ctx: C; req: WGI_REQUEST; res: WGI_RESPONSE_BUFFER)
+ deferred
+ end
+
+ pre_execute (ctx: C; req: WGI_REQUEST; res: WGI_RESPONSE_BUFFER)
+ do
+ end
+
+ post_execute (ctx: C; req: WGI_REQUEST; res: WGI_RESPONSE_BUFFER)
+ do
+ end
+
+ rescue_execute (ctx: C; req: WGI_REQUEST; res: WGI_RESPONSE_BUFFER)
+ do
+ post_execute (ctx, req, res)
+ end
+
+ execute_unauthorized (ctx: C; req: WGI_REQUEST; res: WGI_RESPONSE_BUFFER)
do
res.set_status_code ({HTTP_STATUS_CODE}.unauthorized)
- res.write_header ({HTTP_STATUS_CODE}.unauthorized, <<["WWW-Authenticate", "Basic realm=%"Eiffel auth%""]>>)
+ res.write_header ({HTTP_STATUS_CODE}.unauthorized, Void)
res.write_string ("Unauthorized")
end
-
feature {NONE} -- Implementation
supported_formats: INTEGER
@@ -152,6 +194,116 @@ feature -- Element change: formats
supported_formats := supported_formats | f
end
+feature {NONE} -- Implementation
+
+ supported_request_methods: INTEGER
+ -- Support request method such as GET, POST, ...
+
+feature {NONE} -- Status report
+
+ request_method_id_supported (a_id: INTEGER): BOOLEAN
+ do
+ Result := (supported_request_methods & a_id) = a_id
+ end
+
+ request_method_name_supported (n: STRING): BOOLEAN
+ -- Is request method `n' supported?
+ do
+ Result := request_method_id_supported (request_method_constants.method_id (n))
+ end
+
+ request_method_constants: HTTP_REQUEST_METHOD_CONSTANTS
+ once
+ create Result
+ end
+
+feature -- Status report
+
+ supported_request_method_names: LIST [STRING]
+ -- Support request method such as GET, POST, ...
+ do
+ create {LINKED_LIST [STRING]} Result.make
+ if method_get_supported then
+ Result.extend (request_method_constants.method_get_name)
+ end
+ if method_post_supported then
+ Result.extend (request_method_constants.method_post_name)
+ end
+ if method_put_supported then
+ Result.extend (request_method_constants.method_put_name)
+ end
+ if method_delete_supported then
+ Result.extend (request_method_constants.method_delete_name)
+ end
+ if method_head_supported then
+ Result.extend (request_method_constants.method_head_name)
+ end
+ end
+
+ method_get_supported: BOOLEAN
+ do
+ Result := request_method_id_supported ({HTTP_REQUEST_METHOD_CONSTANTS}.method_get)
+ end
+
+ method_post_supported: BOOLEAN
+ do
+ Result := request_method_id_supported ({HTTP_REQUEST_METHOD_CONSTANTS}.method_post)
+ end
+
+ method_put_supported: BOOLEAN
+ do
+ Result := request_method_id_supported ({HTTP_REQUEST_METHOD_CONSTANTS}.method_put)
+ end
+
+ method_delete_supported: BOOLEAN
+ do
+ Result := request_method_id_supported ({HTTP_REQUEST_METHOD_CONSTANTS}.method_delete)
+ end
+
+ method_head_supported: BOOLEAN
+ do
+ Result := request_method_id_supported ({HTTP_REQUEST_METHOD_CONSTANTS}.method_head)
+ end
+
+feature -- Element change: request methods
+
+ reset_supported_request_methods
+ do
+ supported_request_methods := 0
+ end
+
+ enable_request_method_get
+ do
+ enable_request_method ({HTTP_REQUEST_METHOD_CONSTANTS}.method_get)
+ end
+
+ enable_request_method_post
+ do
+ enable_request_method ({HTTP_REQUEST_METHOD_CONSTANTS}.method_post)
+ end
+
+ enable_request_method_put
+ do
+ enable_request_method ({HTTP_REQUEST_METHOD_CONSTANTS}.method_put)
+ end
+
+ enable_request_method_delete
+ do
+ enable_request_method ({HTTP_REQUEST_METHOD_CONSTANTS}.method_delete)
+ end
+
+ enable_request_method_head
+ do
+ enable_request_method ({HTTP_REQUEST_METHOD_CONSTANTS}.method_head)
+ end
+
+ enable_request_method (m: INTEGER)
+ do
+ supported_request_methods := supported_request_methods | m
+ end
+
+
+
note
copyright: "Copyright (c) 1984-2011, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
diff --git a/library/server/request/rest/src/uri/rest_request_uri_routing_handler_i.e b/library/server/request/rest/src/uri/rest_request_uri_routing_handler_i.e
index 80365a96..86c23462 100644
--- a/library/server/request/rest/src/uri/rest_request_uri_routing_handler_i.e
+++ b/library/server/request/rest/src/uri/rest_request_uri_routing_handler_i.e
@@ -29,11 +29,17 @@ feature -- Status report
feature -- Execution
- execute (a_hdl_context: C; req: WGI_REQUEST; res: WGI_RESPONSE_BUFFER)
+ execute (ctx: C; req: WGI_REQUEST; res: WGI_RESPONSE_BUFFER)
do
- Precursor {REST_REQUEST_HANDLER} (a_hdl_context, req, res)
+ Precursor {REST_REQUEST_HANDLER} (ctx, req, res)
end
+ execute_application (ctx: C; req: WGI_REQUEST; res: WGI_RESPONSE_BUFFER)
+ do
+ check should_not_occur: False end
+ end
+
+
feature {NONE} -- Routing
router: REST_REQUEST_URI_ROUTER_I [H, C]
diff --git a/library/server/request/rest/src/uri_template/rest_request_uri_template_routing_handler_i.e b/library/server/request/rest/src/uri_template/rest_request_uri_template_routing_handler_i.e
index e622203f..3cece40b 100644
--- a/library/server/request/rest/src/uri_template/rest_request_uri_template_routing_handler_i.e
+++ b/library/server/request/rest/src/uri_template/rest_request_uri_template_routing_handler_i.e
@@ -25,13 +25,25 @@ create
feature -- Status report
- authentication_required: BOOLEAN
+ authentication_required (req: WGI_REQUEST): BOOLEAN
+ do
+ Result := internal_authentication_required
+ end
+
+feature {NONE} -- Implementation
+
+ internal_authentication_required: BOOLEAN
feature -- Execution
- execute (a_hdl_context: C; req: WGI_REQUEST; res: WGI_RESPONSE_BUFFER)
+ execute (ctx: C; req: WGI_REQUEST; res: WGI_RESPONSE_BUFFER)
do
- Precursor {REST_REQUEST_HANDLER} (a_hdl_context, req, res)
+ Precursor {REST_REQUEST_HANDLER} (ctx, req, res)
+ end
+
+ execute_application (ctx: C; req: WGI_REQUEST; res: WGI_RESPONSE_BUFFER)
+ do
+ check should_not_occur: False end
end
feature {NONE} -- Routing
diff --git a/library/server/request/rest/tests/src/app/app_account_verify_credential.e b/library/server/request/rest/tests/src/app/app_account_verify_credential.e
index 0bb06270..17efb516 100644
--- a/library/server/request/rest/tests/src/app/app_account_verify_credential.e
+++ b/library/server/request/rest/tests/src/app/app_account_verify_credential.e
@@ -35,7 +35,10 @@ feature {NONE} -- Initialization
feature -- Access
- authentication_required: BOOLEAN = True
+ authentication_required (req: WGI_REQUEST): BOOLEAN
+ do
+ Result := True
+ end
feature -- Execution
diff --git a/library/server/request/rest/tests/src/app/app_test.e b/library/server/request/rest/tests/src/app/app_test.e
index af6dc20f..f642977a 100644
--- a/library/server/request/rest/tests/src/app/app_test.e
+++ b/library/server/request/rest/tests/src/app/app_test.e
@@ -32,7 +32,9 @@ feature {NONE} -- Initialization
feature -- Access
- authentication_required: BOOLEAN = False
+ authentication_required (req: WGI_REQUEST): BOOLEAN
+ do
+ end
feature -- Execution
diff --git a/library/server/request/rest/tests/src/handler/app_request_handler.e b/library/server/request/rest/tests/src/handler/app_request_handler.e
index d4434670..01e78d9c 100644
--- a/library/server/request/rest/tests/src/handler/app_request_handler.e
+++ b/library/server/request/rest/tests/src/handler/app_request_handler.e
@@ -11,6 +11,13 @@ inherit
APP_REQUEST_HELPER
+feature {NONE} -- Initialization
+
+ initialize
+ -- Initialize various attributes
+ do
+ end
+
feature {NONE} -- Implementation
wgi_value_iteration_to_string (cur: ITERATION_CURSOR [WGI_VALUE]; using_pre: BOOLEAN): STRING_8
diff --git a/library/server/request/router/src/request_agent_handler.e b/library/server/request/router/src/request_agent_handler.e
index 962cebc4..66704ece 100644
--- a/library/server/request/router/src/request_agent_handler.e
+++ b/library/server/request/router/src/request_agent_handler.e
@@ -18,7 +18,6 @@ feature -- Initialization
make (act: like action)
do
action := act
- initialize
end
feature -- Access
@@ -27,7 +26,7 @@ feature -- Access
feature -- Execution
- execute_application (ctx: C; req: WGI_REQUEST; res: WGI_RESPONSE_BUFFER)
+ execute (ctx: C; req: WGI_REQUEST; res: WGI_RESPONSE_BUFFER)
do
action.call ([ctx, req, res])
end
diff --git a/library/server/request/router/src/request_handler.e b/library/server/request/router/src/request_handler.e
index a9908338..30f0fc54 100644
--- a/library/server/request/router/src/request_handler.e
+++ b/library/server/request/router/src/request_handler.e
@@ -15,24 +15,12 @@ inherit
{NONE} all
end
-feature {NONE} -- Initialization
-
- initialize
- -- Initialize various attributes
- do
- end
-
-feature -- Access
-
- description: detachable STRING
- -- Optional descriptiong
-
feature -- Status report
is_valid_context (req: WGI_REQUEST): BOOLEAN
-- Is `req' valid context for current handler?
do
- Result := request_method_name_supported (req.request_method)
+ Result := True
end
feature -- Execution
@@ -41,49 +29,9 @@ feature -- Execution
-- Execute request handler
require
is_valid_context: is_valid_context (req)
- local
- rescued: BOOLEAN
- do
- if not rescued then
- if request_method_name_supported (req.request_method) then
- pre_execute (ctx, req, res)
- execute_application (ctx, req, res)
- post_execute (ctx, req, res)
- else
- execute_request_method_not_allowed (req, res, supported_request_method_names)
- end
- else
- rescue_execute (ctx, req, res)
- end
- rescue
- rescued := True
- retry
- end
-
- execute_application (ctx: C; req: WGI_REQUEST; res: WGI_RESPONSE_BUFFER)
- -- Execute request handler
deferred
end
- pre_execute (ctx: C; req: WGI_REQUEST; res: WGI_RESPONSE_BUFFER)
- -- Operation processed before `execute'
- do
- --| To be redefined if needed
- end
-
- post_execute (ctx: C; req: WGI_REQUEST; res: WGI_RESPONSE_BUFFER)
- -- Operation processed after `execute'
- do
- --| To be redefined if needed
- end
-
- rescue_execute (ctx: C; req: WGI_REQUEST; res: WGI_RESPONSE_BUFFER)
- -- Operation processed after a rescue
- do
- --| To be redefined if needed
- post_execute (ctx, req, res)
- end
-
feature -- Execution: report
url (req: WGI_REQUEST; a_base: detachable READABLE_STRING_8; args: detachable STRING; abs: BOOLEAN): STRING
@@ -117,122 +65,6 @@ feature -- Execution: report
result_attached: Result /= Void
end
-feature -- Element change
-
- set_description (s: like description)
- -- Set `description' to `s'
- do
- description := s
- end
-
-feature {NONE} -- Implementation
-
- supported_request_methods: INTEGER
- -- Support request method such as GET, POST, ...
-
-feature {NONE} -- Status report
-
- request_method_id_supported (a_id: INTEGER): BOOLEAN
- do
- Result := (supported_request_methods & a_id) = a_id
- end
-
- request_method_name_supported (n: STRING): BOOLEAN
- -- Is request method `n' supported?
- do
- Result := request_method_id_supported (request_method_constants.method_id (n))
- end
-
- request_method_constants: HTTP_REQUEST_METHOD_CONSTANTS
- once
- create Result
- end
-
-feature -- Status report
-
- supported_request_method_names: LIST [STRING]
- -- Support request method such as GET, POST, ...
- do
- create {LINKED_LIST [STRING]} Result.make
- if method_get_supported then
- Result.extend (request_method_constants.method_get_name)
- end
- if method_post_supported then
- Result.extend (request_method_constants.method_post_name)
- end
- if method_put_supported then
- Result.extend (request_method_constants.method_put_name)
- end
- if method_delete_supported then
- Result.extend (request_method_constants.method_delete_name)
- end
- if method_head_supported then
- Result.extend (request_method_constants.method_head_name)
- end
- end
-
- method_get_supported: BOOLEAN
- do
- Result := request_method_id_supported ({HTTP_REQUEST_METHOD_CONSTANTS}.method_get)
- end
-
- method_post_supported: BOOLEAN
- do
- Result := request_method_id_supported ({HTTP_REQUEST_METHOD_CONSTANTS}.method_post)
- end
-
- method_put_supported: BOOLEAN
- do
- Result := request_method_id_supported ({HTTP_REQUEST_METHOD_CONSTANTS}.method_put)
- end
-
- method_delete_supported: BOOLEAN
- do
- Result := request_method_id_supported ({HTTP_REQUEST_METHOD_CONSTANTS}.method_delete)
- end
-
- method_head_supported: BOOLEAN
- do
- Result := request_method_id_supported ({HTTP_REQUEST_METHOD_CONSTANTS}.method_head)
- end
-
-feature -- Element change: request methods
-
- reset_supported_request_methods
- do
- supported_request_methods := 0
- end
-
- enable_request_method_get
- do
- enable_request_method ({HTTP_REQUEST_METHOD_CONSTANTS}.method_get)
- end
-
- enable_request_method_post
- do
- enable_request_method ({HTTP_REQUEST_METHOD_CONSTANTS}.method_post)
- end
-
- enable_request_method_put
- do
- enable_request_method ({HTTP_REQUEST_METHOD_CONSTANTS}.method_put)
- end
-
- enable_request_method_delete
- do
- enable_request_method ({HTTP_REQUEST_METHOD_CONSTANTS}.method_delete)
- end
-
- enable_request_method_head
- do
- enable_request_method ({HTTP_REQUEST_METHOD_CONSTANTS}.method_head)
- end
-
- enable_request_method (m: INTEGER)
- do
- supported_request_methods := supported_request_methods | m
- end
-
note
copyright: "2011-2011, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
diff --git a/library/server/request/router/src/request_routing_handler.e b/library/server/request/router/src/request_routing_handler.e
index 117dba77..19940f5f 100644
--- a/library/server/request/router/src/request_routing_handler.e
+++ b/library/server/request/router/src/request_routing_handler.e
@@ -13,7 +13,7 @@ inherit
feature -- Execution
- execute_application (ctx: C; req: WGI_REQUEST; res: WGI_RESPONSE_BUFFER)
+ execute (ctx: C; req: WGI_REQUEST; res: WGI_RESPONSE_BUFFER)
-- Execute request handler
local
hdl: detachable H