Added data and file for post and put request methods
This commit is contained in:
@@ -17,7 +17,7 @@ feature {NONE} -- Initialization
|
||||
do
|
||||
create headers.make (2)
|
||||
create query_parameters.make (5)
|
||||
create form_data_parameters.make (10)
|
||||
create form_parameters.make (10)
|
||||
end
|
||||
|
||||
make_with_credentials_required
|
||||
@@ -36,7 +36,7 @@ feature -- Access
|
||||
|
||||
query_parameters: HASH_TABLE [READABLE_STRING_32, READABLE_STRING_8]
|
||||
|
||||
form_data_parameters: HASH_TABLE [READABLE_STRING_32, READABLE_STRING_8]
|
||||
form_parameters: HASH_TABLE [READABLE_STRING_32, READABLE_STRING_8]
|
||||
|
||||
upload_data: detachable READABLE_STRING_8
|
||||
|
||||
@@ -46,7 +46,7 @@ feature -- Status report
|
||||
|
||||
has_form_data: BOOLEAN
|
||||
do
|
||||
Result := not form_data_parameters.is_empty
|
||||
Result := not form_parameters.is_empty
|
||||
end
|
||||
|
||||
has_upload_data: BOOLEAN
|
||||
@@ -66,9 +66,9 @@ feature -- Element change
|
||||
query_parameters.force (v, k)
|
||||
end
|
||||
|
||||
add_form_data_parameter (k: READABLE_STRING_8; v: READABLE_STRING_32)
|
||||
add_form_parameter (k: READABLE_STRING_8; v: READABLE_STRING_32)
|
||||
do
|
||||
form_data_parameters.force (v, k)
|
||||
form_parameters.force (v, k)
|
||||
end
|
||||
|
||||
set_credentials_required (b: BOOLEAN)
|
||||
|
||||
@@ -45,7 +45,19 @@ feature -- Basic operation
|
||||
deferred
|
||||
end
|
||||
|
||||
put (a_path: READABLE_STRING_8; ctx: detachable HTTP_CLIENT_REQUEST_CONTEXT; fn: detachable READABLE_STRING_8): HTTP_CLIENT_RESPONSE
|
||||
post_file (a_path: READABLE_STRING_8; ctx: detachable HTTP_CLIENT_REQUEST_CONTEXT; fn: detachable READABLE_STRING_8): HTTP_CLIENT_RESPONSE
|
||||
deferred
|
||||
end
|
||||
|
||||
post_multipart (a_path: READABLE_STRING_8; ctx: detachable HTTP_CLIENT_REQUEST_CONTEXT; data: detachable READABLE_STRING_8; fn: detachable READABLE_STRING_8): HTTP_CLIENT_RESPONSE
|
||||
deferred
|
||||
end
|
||||
|
||||
put (a_path: READABLE_STRING_8; ctx: detachable HTTP_CLIENT_REQUEST_CONTEXT; data: detachable READABLE_STRING_8): HTTP_CLIENT_RESPONSE
|
||||
deferred
|
||||
end
|
||||
|
||||
put_file (a_path: READABLE_STRING_8; ctx: detachable HTTP_CLIENT_REQUEST_CONTEXT; fn: detachable READABLE_STRING_8): HTTP_CLIENT_RESPONSE
|
||||
deferred
|
||||
end
|
||||
|
||||
|
||||
@@ -124,42 +124,38 @@ feature -- Execution
|
||||
end
|
||||
|
||||
if ctx /= Void and then ctx.has_form_data then
|
||||
if attached ctx.form_data_parameters as l_posts and then not l_posts.is_empty then
|
||||
if attached ctx.form_parameters as l_forms and then not l_forms.is_empty then
|
||||
-- curl_easy.set_debug_function (curl_handle)
|
||||
-- curl_easy.setopt_integer (curl_handle, {CURL_OPT_CONSTANTS}.curlopt_verbose, 1)
|
||||
|
||||
create l_form.make
|
||||
create l_last.make
|
||||
from
|
||||
l_posts.start
|
||||
l_forms.start
|
||||
until
|
||||
l_posts.after
|
||||
l_forms.after
|
||||
loop
|
||||
curl.formadd_string_string (l_form, l_last, {CURL_FORM_CONSTANTS}.CURLFORM_COPYNAME, l_posts.key_for_iteration, {CURL_FORM_CONSTANTS}.CURLFORM_COPYCONTENTS, l_posts.item_for_iteration, {CURL_FORM_CONSTANTS}.CURLFORM_END)
|
||||
l_posts.forth
|
||||
curl.formadd_string_string (l_form, l_last, {CURL_FORM_CONSTANTS}.CURLFORM_COPYNAME, l_forms.key_for_iteration, {CURL_FORM_CONSTANTS}.CURLFORM_COPYCONTENTS, l_forms.item_for_iteration, {CURL_FORM_CONSTANTS}.CURLFORM_END)
|
||||
l_forms.forth
|
||||
end
|
||||
l_last.release_item
|
||||
curl_easy.setopt_form (curl_handle, {CURL_OPT_CONSTANTS}.curlopt_httppost, l_form)
|
||||
end
|
||||
end
|
||||
if ctx /= Void then
|
||||
if
|
||||
request_method.is_case_insensitive_equal ("POST") and then
|
||||
ctx.has_upload_data and then attached ctx.upload_data as l_upload_data
|
||||
then
|
||||
curl_easy.setopt_string (curl_handle, {CURL_OPT_CONSTANTS}.curlopt_postfields, l_upload_data)
|
||||
curl_easy.setopt_integer (curl_handle, {CURL_OPT_CONSTANTS}.curlopt_postfieldsize, l_upload_data.count)
|
||||
elseif
|
||||
request_method.is_case_insensitive_equal ("PUT") and then
|
||||
ctx.has_upload_filename and then attached ctx.upload_filename as l_upload_filename
|
||||
then
|
||||
-- curl_easy.setopt_string (curl_handle, {CURL_OPT_CONSTANTS}.curlopt_postfields, l_upload_data)
|
||||
-- curl_easy.setopt_integer (curl_handle, {CURL_OPT_CONSTANTS}.curlopt_postfieldsize, l_upload_data.count)
|
||||
if request_method.is_case_insensitive_equal ("POST") or request_method.is_case_insensitive_equal ("PUT") then
|
||||
if ctx.has_upload_data and then attached ctx.upload_data as l_upload_data then
|
||||
curl_easy.setopt_string (curl_handle, {CURL_OPT_CONSTANTS}.curlopt_postfields, l_upload_data)
|
||||
curl_easy.setopt_integer (curl_handle, {CURL_OPT_CONSTANTS}.curlopt_postfieldsize, l_upload_data.count)
|
||||
end
|
||||
if ctx.has_upload_filename and then attached ctx.upload_filename as l_upload_filename then
|
||||
-- curl_easy.setopt_string (curl_handle, {CURL_OPT_CONSTANTS}.curlopt_postfields, l_upload_data)
|
||||
-- curl_easy.setopt_integer (curl_handle, {CURL_OPT_CONSTANTS}.curlopt_postfieldsize, l_upload_data.count)
|
||||
--| Not Yet Implemented
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
curl.global_init
|
||||
if attached headers as l_headers then
|
||||
across
|
||||
|
||||
@@ -39,23 +39,55 @@ feature -- Basic operation
|
||||
Result := execute_request (req, ctx)
|
||||
end
|
||||
|
||||
post (a_path: READABLE_STRING_8; a_ctx: detachable HTTP_CLIENT_REQUEST_CONTEXT; a_data: detachable READABLE_STRING_8): HTTP_CLIENT_RESPONSE
|
||||
post (a_path: READABLE_STRING_8; a_ctx: detachable HTTP_CLIENT_REQUEST_CONTEXT; data: detachable READABLE_STRING_8): HTTP_CLIENT_RESPONSE
|
||||
do
|
||||
Result := post_multipart (a_path, a_ctx, data, Void)
|
||||
end
|
||||
|
||||
post_file (a_path: READABLE_STRING_8; a_ctx: detachable HTTP_CLIENT_REQUEST_CONTEXT; fn: detachable READABLE_STRING_8): HTTP_CLIENT_RESPONSE
|
||||
do
|
||||
Result := post_multipart (a_path, a_ctx, Void, fn)
|
||||
end
|
||||
|
||||
post_multipart (a_path: READABLE_STRING_8; a_ctx: detachable HTTP_CLIENT_REQUEST_CONTEXT; data: detachable READABLE_STRING_8; fn: detachable READABLE_STRING_8): HTTP_CLIENT_RESPONSE
|
||||
local
|
||||
req: HTTP_CLIENT_REQUEST
|
||||
ctx: detachable HTTP_CLIENT_REQUEST_CONTEXT
|
||||
do
|
||||
create {LIBCURL_HTTP_CLIENT_REQUEST} req.make (base_url + a_path, "POST", Current)
|
||||
ctx := a_ctx
|
||||
if a_data /= Void then
|
||||
if data /= Void then
|
||||
if ctx = Void then
|
||||
create ctx.make
|
||||
end
|
||||
ctx.set_upload_data (a_data)
|
||||
ctx.set_upload_data (data)
|
||||
end
|
||||
if fn /= Void then
|
||||
if ctx = Void then
|
||||
create ctx.make
|
||||
end
|
||||
ctx.set_upload_filename (fn)
|
||||
end
|
||||
Result := execute_request (req, ctx)
|
||||
end
|
||||
|
||||
put (a_path: READABLE_STRING_8; a_ctx: detachable HTTP_CLIENT_REQUEST_CONTEXT; fn: detachable READABLE_STRING_8): HTTP_CLIENT_RESPONSE
|
||||
put (a_path: READABLE_STRING_8; a_ctx: detachable HTTP_CLIENT_REQUEST_CONTEXT; data: detachable READABLE_STRING_8): HTTP_CLIENT_RESPONSE
|
||||
local
|
||||
req: HTTP_CLIENT_REQUEST
|
||||
ctx: detachable HTTP_CLIENT_REQUEST_CONTEXT
|
||||
do
|
||||
create {LIBCURL_HTTP_CLIENT_REQUEST} req.make (base_url + a_path, "PUT", Current)
|
||||
ctx := a_ctx
|
||||
if data /= Void then
|
||||
if ctx = Void then
|
||||
create ctx.make
|
||||
end
|
||||
ctx.set_upload_data (data)
|
||||
end
|
||||
Result := execute_request (req, ctx)
|
||||
end
|
||||
|
||||
put_file (a_path: READABLE_STRING_8; a_ctx: detachable HTTP_CLIENT_REQUEST_CONTEXT; fn: detachable READABLE_STRING_8): HTTP_CLIENT_RESPONSE
|
||||
local
|
||||
req: HTTP_CLIENT_REQUEST
|
||||
ctx: detachable HTTP_CLIENT_REQUEST_CONTEXT
|
||||
|
||||
Reference in New Issue
Block a user