1---
2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
3SPDX-License-Identifier: curl
4Title: CURLINFO_CONTENT_TYPE
5Section: 3
6Source: libcurl
7See-also:
8  - CURLOPT_HEADERFUNCTION (3)
9  - curl_easy_getinfo (3)
10  - curl_easy_header (3)
11  - curl_easy_setopt (3)
12Protocol:
13  - HTTP
14---
15
16# NAME
17
18CURLINFO_CONTENT_TYPE - get Content-Type
19
20# SYNOPSIS
21
22~~~c
23#include <curl/curl.h>
24
25CURLcode curl_easy_getinfo(CURL *handle, CURLINFO_CONTENT_TYPE, char **ct);
26~~~
27
28# DESCRIPTION
29
30Pass a pointer to a char pointer to receive the content-type of the downloaded
31object. This is the value read from the Content-Type: field. If you get NULL,
32it means that the server did not send a valid Content-Type header or that the
33protocol used does not support this.
34
35The **ct** pointer is set to NULL or pointing to private memory. You MUST
36NOT free it - it gets freed when you call curl_easy_cleanup(3) on the
37corresponding CURL handle.
38
39The modern way to get this header from a response is to instead use the
40curl_easy_header(3) function.
41
42# EXAMPLE
43
44~~~c
45int main(void)
46{
47  CURL *curl = curl_easy_init();
48  if(curl) {
49    CURLcode res;
50    curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
51
52    res = curl_easy_perform(curl);
53
54    if(!res) {
55      /* extract the content-type */
56      char *ct = NULL;
57      res = curl_easy_getinfo(curl, CURLINFO_CONTENT_TYPE, &ct);
58      if(!res && ct) {
59        printf("Content-Type: %s\n", ct);
60      }
61    }
62    curl_easy_cleanup(curl);
63  }
64}
65~~~
66
67# AVAILABILITY
68
69Added in 7.9.4
70
71# RETURN VALUE
72
73Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not.
74