Skip to content

Instantly share code, notes, and snippets.

@mj
Created March 6, 2013 20:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mj/5102778 to your computer and use it in GitHub Desktop.
Save mj/5102778 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <curl/curl.h>
/*
* $ gcc -Wall -L ./lib/.libs/ -I./include/ -lcurl https-proxy-test.c -o https-proxy-test
* $ ./https-proxy-test
*/
#define VERBOSE 0
size_t WriteOutput(void *ptr, size_t size, size_t nmemb, void *stream);
size_t WriteHeader(void *ptr, size_t size, size_t nmemb, void *stream);
long realHeaderSize = 0;
int main(int argc, char *argv[])
{
CURL *curl;
long headerSize;
#if VERBOSE > 0
curl_version_info_data *data = curl_version_info(CURLVERSION_NOW);
printf("libcurl version: %s\n\n", data->version);
#endif
curl_global_init(CURL_GLOBAL_ALL);
curl = curl_easy_init();
curl_easy_setopt(curl, CURLOPT_PROXY, "proxy:8080");
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, *WriteOutput);
curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, *WriteHeader);
curl_easy_setopt(curl, CURLOPT_URL, "https://www.google.com/");
curl_easy_perform(curl);
curl_easy_getinfo(curl, CURLINFO_HEADER_SIZE, &headerSize);
printf("header length is ........: %lu\n", headerSize);
printf("header length should be..: %lu\n", realHeaderSize);
return 0;
}
size_t WriteOutput(void *ptr, size_t size, size_t nmemb, void *stream)
{
return nmemb * size;
}
size_t WriteHeader(void *ptr, size_t size, size_t nmemb, void *stream)
{
realHeaderSize += size * nmemb;
#if VERBOSE > 1
printf("%s", (char *)(ptr));
#endif
return nmemb * size;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment