Post transfer info

Remember how libcurl transfers are associated with easy handles. Each transfer has such a handle and when a transfer is completed, before the handle is cleaned or reused for another transfer, it can be used to extract information from the previous operation.

Your friend for doing this is called curl_easy_getinfo() and you tell it which specific information you are interested in and it returns that if it can.

When you use this function, you pass in the easy handle, which information you want and a pointer to a variable to hold the answer. You must pass in a pointer to a variable of the correct type or you risk that things go side-ways. These information values are designed to be provided after the transfer is completed.

The data you receive can be a long, a 'char *', a 'struct curl_slist *', a double or a socket.

This is how you extract the Content-Type: value from the previous HTTP transfer:

CURLcode res;
char *content_type;
res = curl_easy_getinfo(curl, CURLINFO_CONTENT_TYPE, &content_type);

If you want to extract the local port number that was used in that connection:

CURLcode res;
long port_number;
res = curl_easy_getinfo(curl, CURLINFO_LOCAL_PORT, &port_number);

Available information

Getinfo optionTypeDescription
CURLINFO_ACTIVESOCKETcurl_socket_tThe session's active socket
CURLINFO_APPCONNECT_TIMEdoubleTime from start until SSL/SSH handshake completed
CURLINFO_APPCONNECT_TIME_Tcurl_off_tTime from start until SSL/SSH handshake completed (in microseconds)
CURLINFO_CAINFOchar *Path to the default CA file libcurl is built to use
CURLINFO_CAPATHchar *Path to the CA directory libcurl is built to use
CURLINFO_CERTINFOstruct curl_slist *Certificate chain
CURLINFO_CONDITION_UNMETlongWhether or not a time conditional was met
CURLINFO_CONNECT_TIMEdoubleTime from start until remote host or proxy completed
CURLINFO_CONNECT_TIME_Tcurl_off_tTime from start until remote host or proxy completed (in microseconds)
CURLINFO_CONN_IDcurl_off_tNumerical id of the current connection (meant for callbacks)
CURLINFO_CONTENT_LENGTH_DOWNLOADdoubleContent length from the Content-Length header
CURLINFO_CONTENT_LENGTH_DOWNLOAD_Tcurl_off_tContent length from the Content-Length header
CURLINFO_CONTENT_LENGTH_UPLOADdoubleUpload size
CURLINFO_CONTENT_LENGTH_UPLOAD_Tcurl_off_tUpload size
CURLINFO_CONTENT_TYPEchar *Content type from the Content-Type header
CURLINFO_COOKIELISTstruct curl_slist *List of all known cookies
CURLINFO_EFFECTIVE_METHODchar *Last used HTTP request method
CURLINFO_EFFECTIVE_URLchar *Last used URL
CURLINFO_FILETIMElongRemote time of the retrieved document
CURLINFO_FILETIME_Tcurl_off_tRemote time of the retrieved document
CURLINFO_FTP_ENTRY_PATHchar *The entry path after logging in to an FTP server
CURLINFO_HEADER_SIZElongNumber of bytes of all headers received
CURLINFO_HTTP_CONNECTCODElongLast proxy CONNECT response code
CURLINFO_HTTP_VERSIONlongThe HTTP version used in the connection
CURLINFO_HTTPAUTH_AVAILlongAvailable HTTP authentication methods (bitmask)
CURLINFO_LASTSOCKETlongLast socket used
CURLINFO_LOCAL_IPchar *Local-end IP address of last connection
CURLINFO_LOCAL_PORTlongLocal-end port of last connection
CURLINFO_NAMELOOKUP_TIMEdoubleTime from start until name resolving completed
CURLINFO_NAMELOOKUP_TIME_Tcurl_off_tTime from start until name resolving completed (in microseconds)
CURLINFO_NUM_CONNECTSlongNumber of new successful connections used for previous transfer
CURLINFO_OS_ERRNOlongThe errno from the last failure to connect
CURLINFO_PRETRANSFER_TIMEdoubleTime from start until just before the transfer begins
CURLINFO_PRETRANSFER_TIME_Tcurl_off_tTime from start until just before the transfer begins (in microseconds)
CURLINFO_PRIMARY_IPchar *IP address of the last connection
CURLINFO_PRIMARY_PORTlongPort of the last connection
CURLINFO_PRIVATEchar *User's private data pointer
CURLINFO_PROTOCOLlongThe protocol used for the connection
CURLINFO_PROXY_ERRORlongDetailed (SOCKS) proxy error if CURLE_PROXY was returned from the transfer
CURLINFO_PROXY_SSL_VERIFYRESULTlongProxy certificate verification result
CURLINFO_PROXYAUTH_AVAILlongAvailable HTTP proxy authentication methods
CURLINFO_QUEUE_TIME_Tcurl_off_tTime in microseconds this transfer was held in queue waiting to start
CURLINFO_REDIRECT_COUNTlongTotal number of redirects that were followed
CURLINFO_REDIRECT_TIMEdoubleTime taken for all redirect steps before the final transfer
CURLINFO_REDIRECT_TIME_Tcurl_off_tTime taken for all redirect steps before the final transfer (in microseconds)
CURLINFO_REDIRECT_URLchar *URL a redirect would take you to, had you enabled redirects
CURLINFO_REFERERchar *The used request Referer: header
CURLINFO_REQUEST_SIZElongNumber of bytes sent in the issued HTTP requests
CURLINFO_RESPONSE_CODElongLast received response code
CURLINFO_RETRY_AFTERcurl_off_tThe value from the response Retry-After: header
CURLINFO_RTSP_CLIENT_CSEQlongRTSP next expected client CSeq
CURLINFO_RTSP_CSEQ_RECVlongRTSP last received
CURLINFO_RTSP_SERVER_CSEQlongRTSP next expected server CSeq
CURLINFO_RTSP_SESSION_IDchar *RTSP session ID
CURLINFO_SCHEMEchar *The scheme used for the connection
CURLINFO_SIZE_DOWNLOADdoubleNumber of bytes downloaded
CURLINFO_SIZE_DOWNLOAD_Tcurl_off_tNumber of bytes downloaded
CURLINFO_SIZE_UPLOADdoubleNumber of bytes uploaded
CURLINFO_SIZE_UPLOAD_Tcurl_off_tNumber of bytes uploaded
CURLINFO_SPEED_DOWNLOADdoubleAverage download speed
CURLINFO_SPEED_DOWNLOAD_Tcurl_off_tAverage download speed
CURLINFO_SPEED_UPLOADdoubleAverage upload speed
CURLINFO_SPEED_UPLOAD_Tcurl_off_tAverage upload speed
CURLINFO_SSL_ENGINESstruct curl_slist *A list of OpenSSL crypto engines
CURLINFO_SSL_VERIFYRESULTlongCertificate verification result
CURLINFO_STARTTRANSFER_TIMEdoubleTime from start until just when the first byte is received
CURLINFO_STARTTRANSFER_TIME_Tcurl_off_tTime from start until just when the first byte is received (in microseconds)
CURLINFO_TLS_SSL_PTRstruct curl_slist *TLS session info that can be used for further processing
CURLINFO_TOTAL_TIMEdoubleTotal time of previous transfer
CURLINFO_TOTAL_TIME_Tcurl_off_tTotal time of previous transfer (in microseconds)
CURLINFO_XFER_IDcurl_off_tNumerical id of the current transfer (meant for callbacks)