curl_easy_getinfo

Syntax

#include <curl/curl.h>

CURLcode *curl_easy_getinfo(CURL *curl, CURLINFO info, ...);

Parameters

curl Handle to a curl session.
info A constant representing the CURLINFO value to be obtained.
pointer Pointer to a long, a pointer to a char *, a pointer to a struct curl_slist * or a pointer to a double (see the CURLINFO Values list below for details).

Return Values

CURLcode If the operation was successful, CURLE_OK is returned. If CURLE_OK is not returned, the data received cannot be relied upon.

Description

Request internal information from the curl session with this function. The third argument must be a pointer to a long, a pointer to a char *, a pointer to a struct curl_slist * or a pointer to a double (as described further down). The data pointed to will be filled in accordingly and can be relied upon only if the function returns CURLE_OK.

Use this function after a performed transfer if you want to get transfer-oriented data.

NOTE:
Do not free the memory returned by this function unless it is explicitly mentioned below.

CURLINFO Values

The following CURLINFO values can be used to extract specific CURL information:

CURLINFO_EFFECTIVE_URL

Pass a pointer to a char pointer to receive the last used effective URL.

CURLINFO_RESPONSE_CODE

Pass a pointer to a long to receive the last received HTTP or FTP code. This will be zero if no server response code has been received. Note that a proxy's CONNECT response should be read with CURLINFO_HTTP_CONNECTCODE and not this.

CURLINFO_HTTP_CONNECTCODE

Pass a pointer to a long to receive the last received proxy response code to a CONNECT request.

CURLINFO_FILETIME

Pass a pointer to a long to receive the remote time of the retrieved document (in number of seconds since 1 Jan 1970 in the GMT/UTC time zone). If you get -1, it can be because of many reasons (unknown, the server hides it or the server does not support the command that instructs document time etc) and the time of the document is unknown.

NOTE:
Instruct the server to collect this information before the transfer is made, by using the CURLOPT_FILETIME option to curl_easy_setopt or you will unconditionally get a -1 back.

CURLINFO_TOTAL_TIME

Pass a pointer to a double to receive the total time in seconds for the previous transfer, including name resolving, TCP connect etc.

CURLINFO_NAMELOOKUP_TIME

Pass a pointer to a double to receive the time, in seconds, it took from the start until the name resolving was completed.

CURLINFO_CONNECT_TIME

Pass a pointer to a double to receive the time, in seconds, it took from the start until the connect to the remote host (or proxy) was completed.

CURLINFO_APPCONNECT_TIME

Pass a pointer to a double to receive the time, in seconds, it took from the start until the SSL/SSH connect/handshake to the remote host was completed. This time is most often near to the PRETRANSFER time, except for cases such as HTTP pipelining where the pretransfer time can be delayed due to waits in line for the pipeline and more.

CURLINFO_PRETRANSFER_TIME

Pass a pointer to a double to receive the time, in seconds, it took from the start until the file transfer is about to begin. This includes all pre-transfer commands and negotiations that are specific to the particular protocol(s) involved. It does not involve the sending of the protocol- specific request that triggers a transfer.

CURLINFO_STARTTRANSFER_TIME

Pass a pointer to a double to receive the time, in seconds, it took from the start until the first byte is received by libcurl. This includes CURLINFO_PRETRANSFER_TIME and also the time the server needs to calculate the result.

CURLINFO_REDIRECT_TIME

Pass a pointer to a double to receive the total time, in seconds, it took for all redirection steps include name lookup, connect, pretransfer and transfer before final transaction was started. CURLINFO_REDIRECT_TIME contains the complete execution time for multiple redirections.

CURLINFO_REDIRECT_COUNT

Pass a pointer to a long to receive the total number of redirections that were actually followed.

CURLINFO_REDIRECT_URL

Pass a pointer to a char pointer to receive the URL a redirect would take you to if you would enable CURLOPT_FOLLOWLOCATION. This can be useful if using the built-in libcurl redirect logic is not suitable for you but you would still prefer to avoid implementing the figuring out of the new URL.

CURLINFO_SIZE_UPLOAD

Pass a pointer to a double to receive the total amount of bytes that were uploaded.

CURLINFO_SIZE_DOWNLOAD

Pass a pointer to a double to receive the total amount of bytes that were downloaded. The amount is only for the latest transfer and will be reset again for each new transfer.

CURLINFO_SPEED_DOWNLOAD

Pass a pointer to a double to receive the average download speed that curl measured for the complete download. Measured in bytes/second.

CURLINFO_SPEED_UPLOAD

Pass a pointer to a double to receive the average upload speed that curl measured for the complete upload. Measured in bytes/second.

CURLINFO_HEADER_SIZE

Pass a pointer to a long to receive the total size of all the headers received. Measured in number of bytes.

CURLINFO_REQUEST_SIZE

Pass a pointer to a long to receive the total size of the issued requests. This is so far only for HTTP requests. Note that this may be more than one request if FOLLOWLOCATION is true.

CURLINFO_SSL_VERIFYRESULT

Pass a pointer to a long to receive the result of the peer certification verification that was requested (using the CURLOPT_NSSL_PEER_VERIFY_OPT option to curl_easy_setopt). This is a detailed error code for peer certificate validation (NSSL_CERT_VALID or NSSL_CERT_V_ERR* from cafe/nssl/nsslclient.h. For information, see Cafe SSL library.

CURLINFO_CONTENT_LENGTH_DOWNLOAD

Pass a pointer to a double to receive the content-length of the download. This is the value read from the Content-Length: field. This returns -1 if the size is not known.

CURLINFO_CONTENT_LENGTH_UPLOAD

Pass a pointer to a double to receive the specified size of the upload. This returns -1 if the size is not known.

CURLINFO_CONTENT_TYPE

Pass a pointer to a char pointer to receive the content-type of the downloaded object. This is the value read from the Content-Type: field. If you get NULL, it indicates that the server did not send a valid Content-Type header or that the protocol used does not support this.

CURLINFO_PRIVATE

Pass a pointer to a char pointer to receive the pointer to the private data associated with the curl handle (set with the CURLOPT_PRIVATE option to curl_easy_setopt). Note that for internal reasons, the value is returned as a char pointer, although effectively being a 'void *'.

CURLINFO_HTTPAUTH_AVAIL

Pass a pointer to a long to receive a bitmask indicating the authentication method(s) available. The meaning of the bits is explained in the CURLOPT_HTTPAUTH option for curl_easy_setopt.

CURLINFO_PROXYAUTH_AVAIL

Pass a pointer to a long to receive a bitmask indicating the authentication method(s) available for your proxy authentication.

CURLINFO_OS_ERRNO

Pass a pointer to a long to receive the errno variable from a connect failure. Note that the value is only set on failure, it is not reset upon a successful operation.

CURLINFO_NUM_CONNECTS

Pass a pointer to a long to receive how many new connections libcurl had to create to achieve the previous transfer (only the successful connects are counted). Combined with CURLINFO_REDIRECT_COUNT you are able to know how many times libcurl successfully reused existing connection(s) or not. For more information, see the Connection Options of curl_easy_setopt on how libcurl tries to make persistent connections to save time.

CURLINFO_PRIMARY_IP

Pass a pointer to a char pointer to receive the pointer to a zero-terminated string holding the IP address of the most recent connection done with this curl handle. This string may be IPv6 if that's enabled. Note that you get a pointer to a memory area that will be reused at next request so you need to copy the string if you want to keep the information.

CURLINFO_PRIMARY_PORT

Pass a pointer to a long to receive the destination port of the most recent connection done with this curl handle.

CURLINFO_LOCAL_IP

Pass a pointer to a char pointer to receive the pointer to a zero-terminated string holding the local (source) IP address of the most recent connection done with this curl handle. This string may be IPv6 if that's enabled. The same restrictions apply as to CURLINFO_PRIMARY_IP.

CURLINFO_LOCAL_PORT

Pass a pointer to a long to receive the local (source) port of the most recent connection done with this curl handle.

CURLINFO_COOKIELIST

Pass a pointer to a struct curl_slist * to receive a linked-list of all cookies cURL knows (expired ones, too). Remember to curl_slist_free_all the list after it has been used. If there are no cookies (cookies for the handle have not been enabled or none have been received) struct curl_slist * will be set to point to NULL.

CURLINFO_LASTSOCKET

Pass a pointer to a long to receive the last socket used by this curl session. If the socket is no longer valid, -1 is returned. When you finish working with the socket, call curl_easy_cleanup as usual and let libcurl close the socket and cleanup other resources associated with the handle. This is typically used in combination with CURLOPT_CONNECT_ONLY.

NOTE:
This API is not working well on win64, since the SOCKET type on win64 is 64-bit large while its 'long' is only 32-bits.

CURLINFO_CONDITION_UNMET

Pass a pointer to a long to receive the number 1 if the condition provided in the previous request did not match (see CURLOPT_TIMECONDITION). If it returns a 1, the reason that data was not in the return is because it did not fulfill the condition. The long value this argument points to will get a zero stored if the condition instead was met.

TIME Values

The following CURLINFO values are used to obtain elapsed time when using curl_easy_perform for file transfers. First a diagram of the relative time milestones is presented, then the specific CURLINFO values of elapsed time are listed.

curl_easy_perform()
     |
     |--NAMELOOKUP
     |--|--CONNECT
     |--|--|--APPCONNECT
     |--|--|--|--PRETRANSFER
     |--|--|--|--|--STARTTRANSFER
     |--|--|--|--|--|--TOTAL
     |--|--|--|--|--|--REDIRECT

NAMELOOKUP

CURLINFO_NAMELOOKUP_TIME. The time it took from the start until the name resolving was completed.

CONNECT

CURLINFO_CONNECT_TIME. The time it took from the start until the connect to the remote host (or proxy) was completed.

APPCONNECT

CURLINFO_APPCONNECT_TIME. The time it took from the start until the SSL connect/handshake with the remote host was completed.

PRETRANSFER

CURLINFO_PRETRANSFER_TIME. The time it took from the start until the file transfer is about to begin. This includes all pre-transfer commands and negotiations that are specific to the particular protocol(s) involved.

STARTTRANSFER

CURLINFO_STARTTRANSFER_TIME. The time it took from the start until the first byte is received by libcurl.

TOTAL

CURLINFO_TOTAL_TIME. Total time of the previous request.

REDIRECT

CURLINFO_REDIRECT_TIME. The time it took for all redirection steps include name lookup, connect, pretransfer and transfer before final transaction was started. So, this is zero if no redirection took place.

Do Not Call From

None.

See Also

HTTP Client Library (libcurl)
libcurl API Functions
libcurl Error Codes
curl_easy_setopt

Revision History

2013/09/18 Conversion
2013/05/08 Automated cleanup pass.
2012/05/04 Initial version.


CONFIDENTIAL