GNURLINFO_CONTENT_TYPE(3)
π GNURLINFO_CONTENT_TYPE(3) π
okay so bestie, this page lives in the curl_easy_getinfo options manual, and itβs here to explain how you get the Content-Type. no cap, itβs a whole vibe.
β¨ NAME β¨
CURLINFO_CONTENT_TYPE β get Content-Type
π SYNOPSIS π
include this header and call this:
#include <gnurl/curl.h>
CURLcode curl_easy_getinfo(CURL *handle, CURLINFO_CONTENT_TYPE, char
**ct);
π¦ DESCRIPTION π¦
okay so 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, it means the server didnβt send a valid Content-Type header or the protocol used doesnβt support this.
the ct pointer will be NULL or pointing to private memory β you MUST NOT free it. it gets freed when you call curl_easy_cleanup(3) on the corresponding CURL handle. periodt. π
π PROTOCOLS π
HTTP(S) β thatβs the whole list, bestie.
π₯ EXAMPLE π₯
hereβs the code vibe check:
CURL *curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "http://example.com");
res = curl_easy_perform(curl);
if(!res) {
/* extract the content-type */
char *ct = NULL;
res = curl_easy_getinfo(curl, CURLINFO_CONTENT_TYPE, &ct);
if(!res && ct) {
printf("Content-Type: %s\n", ct);
}
}
curl_easy_cleanup(curl);
}
β AVAILABILITY β
added in 7.9.4, so itβs been iconic for a minute.
π RETURN VALUE π
returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not. simple as that.
π«Ά SEE ALSO π«Ά
go peek at curl_easy_getinfo(3), curl_easy_setopt(3), (yes, the trailing comma is canon π). iykyk.
xoxo, your Unix bestie π β this page comes from libcurl 7.44.0, dated 1 Sep 2015, and itβs the GNURLINFO_CONTENT_TYPE(3) page. bye bestie π
π¦ where this page comes from
- nixos 26.05: libgnurl 7.72.0
- nixpkgs unstable: libgnurl 7.72.0
- Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms