added support for data in POST request
This commit is contained in:
@@ -38,6 +38,10 @@ feature -- Access
|
||||
|
||||
form_data_parameters: HASH_TABLE [READABLE_STRING_32, READABLE_STRING_8]
|
||||
|
||||
upload_data: detachable READABLE_STRING_8
|
||||
|
||||
upload_filename: detachable READABLE_STRING_8
|
||||
|
||||
feature -- Status report
|
||||
|
||||
has_form_data: BOOLEAN
|
||||
@@ -45,6 +49,16 @@ feature -- Status report
|
||||
Result := not form_data_parameters.is_empty
|
||||
end
|
||||
|
||||
has_upload_data: BOOLEAN
|
||||
do
|
||||
Result := attached upload_data as d and then not d.is_empty
|
||||
end
|
||||
|
||||
has_upload_filename: BOOLEAN
|
||||
do
|
||||
Result := attached upload_filename as fn and then not fn.is_empty
|
||||
end
|
||||
|
||||
feature -- Element change
|
||||
|
||||
add_query_parameter (k: READABLE_STRING_8; v: READABLE_STRING_32)
|
||||
@@ -62,4 +76,18 @@ feature -- Element change
|
||||
credentials_required := b
|
||||
end
|
||||
|
||||
set_upload_data (a_data: like upload_data)
|
||||
require
|
||||
has_no_upload_data: not has_upload_data
|
||||
do
|
||||
upload_data := a_data
|
||||
end
|
||||
|
||||
set_upload_filename (a_fn: like upload_filename)
|
||||
require
|
||||
has_no_upload_filename: not has_upload_filename
|
||||
do
|
||||
upload_filename := a_fn
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -41,11 +41,11 @@ feature -- Basic operation
|
||||
deferred
|
||||
end
|
||||
|
||||
post (a_path: READABLE_STRING_8; ctx: detachable HTTP_CLIENT_REQUEST_CONTEXT): HTTP_CLIENT_RESPONSE
|
||||
post (a_path: READABLE_STRING_8; ctx: detachable HTTP_CLIENT_REQUEST_CONTEXT; data: detachable READABLE_STRING_8): HTTP_CLIENT_RESPONSE
|
||||
deferred
|
||||
end
|
||||
|
||||
put (a_path: READABLE_STRING_8; ctx: detachable HTTP_CLIENT_REQUEST_CONTEXT): HTTP_CLIENT_RESPONSE
|
||||
put (a_path: READABLE_STRING_8; ctx: detachable HTTP_CLIENT_REQUEST_CONTEXT; fn: detachable READABLE_STRING_8): HTTP_CLIENT_RESPONSE
|
||||
deferred
|
||||
end
|
||||
|
||||
|
||||
@@ -142,6 +142,22 @@ feature -- Execution
|
||||
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)
|
||||
--| Not Yet Implemented
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
curl.global_init
|
||||
|
||||
@@ -39,19 +39,35 @@ feature -- Basic operation
|
||||
Result := execute_request (req, ctx)
|
||||
end
|
||||
|
||||
post (a_path: READABLE_STRING_8; ctx: detachable HTTP_CLIENT_REQUEST_CONTEXT): HTTP_CLIENT_RESPONSE
|
||||
post (a_path: READABLE_STRING_8; a_ctx: detachable HTTP_CLIENT_REQUEST_CONTEXT; a_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, "POST", Current)
|
||||
ctx := a_ctx
|
||||
if a_data /= Void then
|
||||
if ctx = Void then
|
||||
create ctx.make
|
||||
end
|
||||
ctx.set_upload_data (a_data)
|
||||
end
|
||||
Result := execute_request (req, ctx)
|
||||
end
|
||||
|
||||
put (a_path: READABLE_STRING_8; ctx: detachable HTTP_CLIENT_REQUEST_CONTEXT): HTTP_CLIENT_RESPONSE
|
||||
put (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
|
||||
do
|
||||
create {LIBCURL_HTTP_CLIENT_REQUEST} req.make (base_url + a_path, "PUT", Current)
|
||||
ctx := a_ctx
|
||||
if fn /= Void then
|
||||
if ctx = Void then
|
||||
create ctx.make
|
||||
end
|
||||
ctx.set_upload_filename (fn)
|
||||
end
|
||||
Result := execute_request (req, ctx)
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user