@@ -29,8 +29,8 @@ module http_client
2929contains
3030 ! Constructor for request_type type.
3131 function new_request (url , method ) result(response)
32- character (len=* ) :: url
33- integer , optional :: method
32+ character (len=* ), intent ( in ) :: url
33+ integer , intent ( in ), optional :: method
3434 type (request_type) :: request
3535 type (response_type) :: response
3636 type (client_type) :: client
@@ -47,24 +47,29 @@ function new_request(url, method) result(response)
4747 end function new_request
4848 ! Constructor for client_type type.
4949 function new_client (request ) result(client)
50+ type (request_type), intent (in ) :: request
5051 type (client_type) :: client
51- type (request_type) :: request
5252
5353 client% request = request
54+
5455 end function new_client
5556
5657 function client_get_response (this ) result(response)
57- class(client_type) :: this
58+ class(client_type), intent ( inout ) :: this
5859 type (response_type), target :: response
5960 integer :: rc
61+
6062 ! logic for populating response using fortran-curl
6163 response% url = this% request% url
62- ! response%method = this%request%method
6364
6465 this% curl_ptr = curl_easy_init()
6566
6667 if (.not. c_associated(this% curl_ptr)) then
67- stop ' Error: curl_easy_init() failed'
68+ response% ok = .false.
69+ response% err_msg = " The initialization of a new easy handle using the 'curl_easy_init()'&
70+ & function failed. This can occur due to insufficient memory available in the system. &
71+ & Additionally, if libcurl is not installed or configured properly on the system"
72+ return
6873 end if
6974 ! setting request URL
7075 rc = curl_easy_setopt(this% curl_ptr, CURLOPT_URL, this% request% url // c_null_char)
@@ -89,7 +94,7 @@ function client_get_response(this) result(response)
8994 end function client_get_response
9095
9196 function client_set_method (this , response ) result(status)
92- class(client_type) :: this
97+ class(client_type), intent ( inout ) :: this
9398 type (response_type), intent (out ) :: response
9499 integer :: status
95100
@@ -144,7 +149,7 @@ function client_response_callback(ptr, size, nmemb, client_data) bind(c)
144149 response% content_length = response% content_length + nmemb
145150 ! Return number of received bytes.
146151 client_response_callback = nmemb
152+
147153 end function client_response_callback
148154
149-
150155end module http_client
0 commit comments