CURLINFO_CONTENT_TYPE(3)
Hey bestie! π This is CURLINFO_CONTENT_TYPE(3) straight from the Library Functions Manual β the page for the Content-Type of response, and yes itβs giving main-character energy. β¨
π NAME π
CURLINFO_CONTENT_TYPE - Content-Type of response π
β¨ SYNOPSIS β¨
#include <curl/curl.h>
CURLcode curl_easy_getinfo(CURL *handle, CURLINFO_CONTENT_TYPE, char **ct);
π DESCRIPTION π
Okay so the whole vibe is: you pass a pointer to a char pointer, and it receives the content-type of the downloaded object. This is literally the value read from the Content-Type: field. Slay. π
If you get NULL, that means the server did not send a valid Content-Type header or the protocol used does not support this. No cap. π«Ά
The ct pointer is NULL or points to private memory. You must not free it. Like, hands off. It gets freed automatically when you call curl_easy_cleanup(3) on the corresponding curl handle. Obsessed with the automatic cleanup, honestly. π§
The modern way to get this header from a response is to instead use the curl_easy_header(3) function. Iconic alternative, iykyk. π
π¦ PROTOCOLS π¦
This functionality affects http only. Periodt. π
πΈ EXAMPLE πΈ
Hereβs the example in all its untouched glory: β
int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
result = curl_easy_perform(curl);
if(!result) {
/* extract the content-type */
char *ct = NULL;
result = curl_easy_getinfo(curl, CURLINFO_CONTENT_TYPE, &ct);
if(!result && ct) {
printf("Content-Type: %s\n", ct);
}
}
curl_easy_cleanup(curl);
}
}
π AVAILABILITY π
Added in curl 7.9.4. π
π₯ RETURN VALUE π₯
curl_easy_getinfo(3) returns a CURLcode indicating success or error. π
CURLE_OK (0) means everything was OK, non-zero means an error occurred β see libcurl-errors(3). π
π SEE ALSO π
These are the besties you should also check out. π«Ά
Mwah π thatβs the whole CURLINFO_CONTENT_TYPE(3) page β brought to you by libcurl and dated 2026-10-12. Bye bestie, go get that content-type! π¦β¨
π¦ where this page comes from
- fedora 44: libcurl-devel 8.18.0-14.fc44 Β· curl
- fedora 44: libcurl-devel 8.18.0-14.fc44 Β· curl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms