Skip to content

Commit f2d655e

Browse files
Resolve remarks addressed by interkosmos.
1 parent a058f3f commit f2d655e

File tree

3 files changed

+19
-16
lines changed

3 files changed

+19
-16
lines changed

example/simple_get.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ program simple_get
33
implicit none
44
type(response_type) :: response
55

6-
response = request(url='https://jsonplaceholder.typicode.com/todos/1')
6+
response = request(url='http://jsonplaceholder.typicode.com/todos/1')
77
if(.not. response%ok) then
88
print *,"Error message : ", response%err_msg
99
else

src/http/http_client.f90

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ module http_client
2929
contains
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-
150155
end module http_client

src/http/http_response.f90

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@ module http_response
33
implicit none
44
! Response Type
55
type, public :: response_type
6-
character(len=:), allocatable :: url,content,method,err_msg
7-
integer :: status_code = 0
8-
integer(kind=c_size_t) :: content_length = 0
9-
logical :: ok = .true.
10-
end type response_type
11-
contains
12-
6+
character(len=:), public, allocatable :: url,content,method,err_msg
7+
integer, public :: status_code = 0
8+
integer(kind=8), public :: content_length = 0
9+
logical, public :: ok = .true.
10+
end type response_type
1311
end module http_response

0 commit comments

Comments
 (0)