Refactor REQUEST_RESOURCE_HANDLER_HELPER to figure out the
transfer encoding: Chunked. Added a new method to retrieve_data independently if the transfer is chunked or not. Updated ORDER_HANLDER to use this new feature. Sync with Jocelyn repo
This commit is contained in:
Submodule contrib/ise_library/cURL updated: ad2a498fc0...2b7043f670
@@ -23,17 +23,19 @@ feature {NONE} -- Initialization
|
||||
do
|
||||
create h.make
|
||||
sess := h.new_session ("http://127.0.0.1:9090")
|
||||
|
||||
-- Create Order
|
||||
print ("%N Create Order %N")
|
||||
resp := create_order (sess)
|
||||
|
||||
|
||||
-- Read the Order
|
||||
print ("%N Read Order %N")
|
||||
l_location := resp.header ("Location")
|
||||
resp := read_order (sess, l_location)
|
||||
|
||||
-- Update the Order
|
||||
|
||||
-- Update the Order
|
||||
if attached resp.body as l_body then
|
||||
body := l_body.as_string_8
|
||||
body.replace_substring_all ("takeAway", "in Shop")
|
||||
@@ -43,11 +45,15 @@ feature {NONE} -- Initialization
|
||||
end
|
||||
|
||||
update_order ( sess: HTTP_CLIENT_SESSION; uri : detachable READABLE_STRING_8; a_body : STRING) : HTTP_CLIENT_RESPONSE
|
||||
local
|
||||
context : HTTP_CLIENT_REQUEST_CONTEXT
|
||||
do
|
||||
create Result.make
|
||||
if attached uri as l_uri then
|
||||
sess.set_base_url (l_uri)
|
||||
Result := sess.put ("", Void, a_body )
|
||||
create context.make
|
||||
context.headers.put ("application/json", "Content-Type")
|
||||
Result := sess.put ("", context, a_body )
|
||||
-- Show headers
|
||||
across
|
||||
Result.headers as l_headers
|
||||
|
||||
@@ -114,8 +114,7 @@ feature -- HTTP Methods
|
||||
do
|
||||
if attached req.orig_path_info as orig_path then
|
||||
id := get_order_id_from_path (orig_path)
|
||||
req.input.read_string (req.content_length_value.as_integer_32)
|
||||
l_put := req.input.last_string
|
||||
l_put := retrieve_data (req)
|
||||
l_order := extract_order_request(l_put)
|
||||
if l_order /= Void and then db_access.orders.has_key (id) then
|
||||
l_order.set_id (id)
|
||||
@@ -234,8 +233,7 @@ feature -- HTTP Methods
|
||||
local
|
||||
l_post: STRING
|
||||
do
|
||||
req.input.read_string (req.content_length_value.as_integer_32)
|
||||
l_post := req.input.last_string
|
||||
l_post := retrieve_data (req)
|
||||
if attached extract_order_request (l_post) as l_order then
|
||||
save_order (l_order)
|
||||
compute_response_post (ctx, req, res, l_order)
|
||||
@@ -358,6 +356,6 @@ feature {NONE} -- Implementation Repository Layer
|
||||
end
|
||||
|
||||
note
|
||||
copyright: "2011-2011, Javier Velilla and others"
|
||||
copyright: "2011-2012, Javier Velilla and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
end
|
||||
|
||||
@@ -43,10 +43,14 @@ feature -- Method Post
|
||||
|
||||
execute_post (ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
do
|
||||
if req.content_length_value > 0 then
|
||||
if req.is_chunked_input then
|
||||
do_post (ctx, req, res)
|
||||
else
|
||||
handle_bad_request_response ("Bad request, content_length empty", ctx, req, res)
|
||||
if req.content_length_value > 0 then
|
||||
do_post (ctx, req, res)
|
||||
else
|
||||
handle_bad_request_response ("Bad request, content_length empty", ctx, req, res)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -59,10 +63,14 @@ feature-- Method Put
|
||||
|
||||
execute_put (ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
do
|
||||
if req.content_length_value > 0 then
|
||||
if req.is_chunked_input then
|
||||
do_put (ctx, req, res)
|
||||
else
|
||||
handle_bad_request_response ("Bad request, content_length empty", ctx, req, res)
|
||||
if req.content_length_value > 0 then
|
||||
do_put (ctx, req, res)
|
||||
else
|
||||
handle_bad_request_response ("Bad request, content_length empty", ctx, req, res)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -155,6 +163,23 @@ feature -- Method Extension Method
|
||||
handle_not_implemented ("Method extension-method not implemented", ctx, req, res)
|
||||
end
|
||||
|
||||
feature -- Retrieve content from WGI_INPUT_STREAM
|
||||
|
||||
retrieve_data ( req : WSF_REQUEST) : STRING
|
||||
-- retrieve the content from the input stream
|
||||
-- handle differents transfers
|
||||
do
|
||||
Result := ""
|
||||
if req.is_chunked_input then
|
||||
if attached req.chunked_input as l_chunked_input then
|
||||
Result := l_chunked_input.data.as_string_8
|
||||
end
|
||||
else
|
||||
req.input.read_string (req.content_length_value.as_integer_32)
|
||||
Result := req.input.last_string
|
||||
end
|
||||
end
|
||||
|
||||
feature -- Handle responses
|
||||
-- TODO Handle Content negotiation.
|
||||
-- The option : Server-driven negotiation: uses request headers to select a variant
|
||||
|
||||
Reference in New Issue
Block a user