title: How to extract header information via CURLOPT_HEADERFUNCTION?
body: <p>I want to extract header information by using the CURLOPT_HEADERFUNCTION in my c++ program.</p>
  <p><a href="https://stackoverflow.com/questions/37516773/how-can-i-use-curlopt-headerfunction-to-read-a-single-response-header-field">How can I use CURLOPT_HEADERFUNCTION to read a single response header field?</a> provides the solution on how to get those header information but I want to know why my code is not working and a possible solution with example.</p>
  <pre><code>//readHeader function which returns the specific header information
  
  size_t readHeader(char* header, size_t size, size_t nitems, void *userdata) {
  Erza oprations; //class which contains string function like startsWith etc
  if (oprations.startsWith(header, &quot;Content-Length:&quot;)) {
      std::string header_in_string = oprations.replaceAll(header, &quot;Content-Length:&quot;, &quot;&quot;);
      long size = atol(header_in_string.c_str());
      file_size = size; // file_size is global variable
      std::cout &lt;&lt; size; // here it is showing correct file size
  }
  else if (oprations.startsWith(header, &quot;Content-Type:&quot;)) {
   // do something 
  }else
   // do something
  return size * nitems;
  }
  // part of main function
  curl = curl_easy_init();
      if (curl) {
          fp = fopen(path, &quot;wb&quot;);
          curl_easy_setopt(curl, CURLOPT_URL, url);
          curl_easy_setopt(curl, CURLOPT_CAINFO, &quot;./ca-bundle.crt&quot;);
          curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, false);
          curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, false);
          curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, readHeader);
          curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
          res = curl_easy_perform(curl);
          curl_easy_cleanup(curl);
  
  fclose(fp);
  std::cout &lt;&lt; file_size; // showing value 0
  </code></pre>
  <p>Getting correct file size in readHeader function but getting 0 bytes in main function.</p>