prepare_request_header_ptr Subroutine

private subroutine prepare_request_header_ptr(header_list_ptr, req_headers)

This subroutine prepares headers in required format(Linked list) for an HTTP request.


This subroutine prepares a linked list of headers for an HTTP request using the fortran-curl package. The function takes an array of pair_type objects(i.e. req_headers) that contain the
key-value pairs of the headers to include in the request. It iterates over the array and constructs a string for each header in the format key:value. The subroutine then appends each string to the linked list using the curl_slist_append function. The resulting linked list is returned via the header_list_ptr argument.

Arguments

Type IntentOptional Attributes Name
type(c_ptr), intent(out) :: header_list_ptr

A Pointer that is allocated and points to a linked list of headers.

type(pair_type), intent(in), allocatable :: req_headers(:)

The headers to be included in the request.


Contents


Source Code

    subroutine prepare_request_header_ptr(header_list_ptr, req_headers)
        
        !!> This subroutine prepares `headers` in required format(Linked list) for an HTTP request.
        !!____
        !!> This subroutine prepares a **linked list** of `headers` for an HTTP request using the 
        !!> [fortran-curl](https://github.com/interkosmos/fortran-curl) package. 
        !!> The function takes an array of `pair_type` objects(i.e. `req_headers`) that contain the  
        !!> **key-value** pairs of the headers to include in the request.
        !!> It iterates over the array and constructs a string for each header in the format **`key:value`**.
        !!> The subroutine then appends each string to the linked list using the `curl_slist_append` function.
        !!> The resulting linked list is returned via the `header_list_ptr` argument.
        
        type(c_ptr), intent(out) :: header_list_ptr
            !! A `Pointer` that is allocated and points to a linked list of headers.
        type(pair_type), allocatable, intent(in) :: req_headers(:)
            !! The `headers` to be included in the request.
        character(:), allocatable :: h_name, h_val, final_header_string
        integer :: i

        do i = 1, size(req_headers)
            h_name = req_headers(i)%name
            h_val = req_headers(i)%value
            final_header_string = h_name // ':' // h_val 
            header_list_ptr = curl_slist_append(header_list_ptr, final_header_string)
        end do
    end subroutine prepare_request_header_ptr