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