Added framework for HTTP-conforming contracts
This commit is contained in:
@@ -23,7 +23,7 @@ inherit
|
||||
|
||||
WSF_RESOURCE_HANDLER_HELPER
|
||||
redefine
|
||||
do_get,
|
||||
do_get_head,
|
||||
do_post,
|
||||
do_put,
|
||||
do_delete
|
||||
@@ -53,27 +53,21 @@ feature -- API DOC
|
||||
|
||||
feature -- HTTP Methods
|
||||
|
||||
do_get (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
-- Using GET to retrieve resource information.
|
||||
-- If the GET request is SUCCESS, we response with
|
||||
-- 200 OK, and a representation of the order
|
||||
-- If the GET request is not SUCCESS, we response with
|
||||
-- 404 Resource not found
|
||||
-- If is a Condition GET and the resource does not change we send a
|
||||
-- 304, Resource not modifed
|
||||
do_get_head (a_req: WSF_REQUEST; a_res: WSF_RESPONSE; a_is_get: BOOLEAN)
|
||||
-- <Precursor>
|
||||
local
|
||||
id : STRING
|
||||
id: STRING
|
||||
do
|
||||
if attached req.orig_path_info as orig_path then
|
||||
if attached a_req.orig_path_info as orig_path then
|
||||
id := get_order_id_from_path (orig_path)
|
||||
if attached retrieve_order (id) as l_order then
|
||||
if is_conditional_get (req, l_order) then
|
||||
handle_resource_not_modified_response ("The resource" + orig_path + "does not change", req, res)
|
||||
if is_conditional_get (a_req, l_order) then
|
||||
handle_resource_not_modified_response ("The resource" + orig_path + "does not change", a_req, a_res)
|
||||
else
|
||||
compute_response_get (req, res, l_order)
|
||||
compute_response_get_head (a_req, a_res, l_order, a_is_get)
|
||||
end
|
||||
else
|
||||
handle_resource_not_found_response ("The following resource" + orig_path + " is not found ", req, res)
|
||||
handle_resource_not_found_response ("The following resource" + orig_path + " is not found ", a_req, a_res)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -93,7 +87,7 @@ feature -- HTTP Methods
|
||||
end
|
||||
end
|
||||
|
||||
compute_response_get (req: WSF_REQUEST; res: WSF_RESPONSE; l_order : ORDER)
|
||||
compute_response_get_head (a_req: WSF_REQUEST; a_res: WSF_RESPONSE; l_order: ORDER; a_is_get: BOOLEAN)
|
||||
local
|
||||
h: HTTP_HEADER
|
||||
l_msg : STRING
|
||||
@@ -105,13 +99,15 @@ feature -- HTTP Methods
|
||||
if attached {JSON_VALUE} json.value (l_order) as jv then
|
||||
l_msg := jv.representation
|
||||
h.put_content_length (l_msg.count)
|
||||
if attached req.request_time as time then
|
||||
if attached a_req.request_time as time then
|
||||
h.add_header ("Date:" + time.formatted_out ("ddd,[0]dd mmm yyyy [0]hh:[0]mi:[0]ss.ff2") + " GMT")
|
||||
end
|
||||
h.add_header ("etag:" + etag_utils.md5_digest (l_order.out))
|
||||
res.set_status_code ({HTTP_STATUS_CODE}.ok)
|
||||
res.put_header_text (h.string)
|
||||
res.put_string (l_msg)
|
||||
a_res.set_status_code ({HTTP_STATUS_CODE}.ok)
|
||||
a_res.put_header_text (h.string)
|
||||
if a_is_get then
|
||||
a_res.put_string (l_msg)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user