@@ -319,11 +319,11 @@ function set_body(curl_ptr, request) result(status)
319319 type (c_ptr) :: mime_ptr, part_ptr
320320
321321 ! if only data is passed
322- if ( len (request% data ) > 0 ) then
322+ if ( allocated (request% data )) then
323323 status = set_postfields(curl_ptr, request% data )
324324
325325 ! if file is passsed
326- else if ( len (request% file% name) > 0 ) then
326+ else if ( allocated (request% file) ) then
327327 mime_ptr = curl_mime_init(curl_ptr)
328328 part_ptr = curl_mime_addpart(mime_ptr)
329329 status = curl_mime_filedata(part_ptr, request% file% value)
@@ -345,14 +345,17 @@ function set_body(curl_ptr, request) result(status)
345345 end if
346346
347347 ! if only form is passed
348- else if (allocated (request% form)) then
348+ else if (allocated (request% form)) then
349349 request% form_encoded_str = prepare_form_encoded_str(curl_ptr, request)
350350 status = set_postfields(curl_ptr, request% form_encoded_str)
351351
352352 ! setting the Content-Type header to application/x-www-form-urlencoded, used for sending form data
353353 if (.not. pair_has_name(request% header, ' Content-Type' )) then
354354 call append_pair(request% header, ' Content-Type' , ' application/x-www-form-urlencoded' )
355355 end if
356+ else
357+ ! No curl function was called so set status to zero.
358+ status = 0
356359 end if
357360
358361 end function set_body
0 commit comments