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