Last active
July 5, 2018 20:49
Revisions
-
jglenn9k revised this gist
Mar 30, 2018 . 1 changed file with 5 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,6 +3,9 @@ #include <cstdio> #include <curl/curl.h> // James Glenn <thedonkdonk@gmail.com> // 2018-03-30 static size_t WriteCallback(void *contents, size_t size, size_t nmemb, void *userp) { ((std::string*)userp)->append((char*)contents, size * nmemb); return size * nmemb; @@ -56,8 +59,8 @@ int main(int argc, char **argv) { if((CURLE_OK == res) && response_code) { printf("Redirected to: %s\n", url); printf("Response Code: %ld\n", response_code); printf("Total Redirects: %ld\n", redirects); printf("Downloaded: %.0f bytes\n", dlsize); printf("Download speed %.0f bytes/sec\n", dlspeed); -
jglenn9k revised this gist
Mar 29, 2018 . 1 changed file with 60 additions and 60 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,74 +4,74 @@ #include <curl/curl.h> static size_t WriteCallback(void *contents, size_t size, size_t nmemb, void *userp) { ((std::string*)userp)->append((char*)contents, size * nmemb); return size * nmemb; } int main(int argc, char **argv) { if (argc != 2) { std::cout << "ERROR - Must provide a URL." << std::endl; return 2; } CURL *curl; CURLcode res; std::string readBuffer; curl = curl_easy_init(); if(curl) { curl_easy_setopt(curl, CURLOPT_HEADER, false); curl_easy_setopt(curl, CURLOPT_ENCODING, "gzip"); curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); curl_easy_setopt(curl, CURLOPT_VERBOSE, false); curl_easy_setopt(curl, CURLOPT_USERAGENT, "Page Speed Checker v1.0"); curl_easy_setopt(curl, CURLOPT_URL, argv[1]); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer); res = curl_easy_perform(curl); if(CURLE_OK == res) { char *url = NULL; curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_URL, &url); long response_code; curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response_code); double dlsize; curl_easy_getinfo(curl, CURLINFO_SIZE_DOWNLOAD, &dlsize); double dlspeed; curl_easy_getinfo(curl, CURLINFO_SPEED_DOWNLOAD, &dlspeed); double namelookup; curl_easy_getinfo(curl, CURLINFO_NAMELOOKUP_TIME, &namelookup); double connect; curl_easy_getinfo(curl, CURLINFO_CONNECT_TIME, &connect); double pretransfer; curl_easy_getinfo(curl, CURLINFO_PRETRANSFER_TIME, &pretransfer); double start; curl_easy_getinfo(curl, CURLINFO_STARTTRANSFER_TIME, &start); double redirect; curl_easy_getinfo(curl, CURLINFO_REDIRECT_TIME, &redirect); double total; curl_easy_getinfo(curl, CURLINFO_TOTAL_TIME, &total); long redirects; curl_easy_getinfo(curl, CURLINFO_REDIRECT_COUNT, &redirects); if((CURLE_OK == res) && response_code) { printf("Redirected to: %s\n", url); printf("Response Code: %d\n", response_code); printf("Total Redirects: %d\n", redirects); printf("Downloaded: %.0f bytes\n", dlsize); printf("Download speed %.0f bytes/sec\n", dlspeed); printf("Name Lookup Time: %.2f\n", namelookup); printf("Connect Time: %.2f\n", connect); printf("Pretransfer Time: %.2f\n", pretransfer); printf("Start Time: %.2f\n", start); printf("Redirect Time: %.2f\n", redirect); printf("Total Time: %.2f\n", total); } } curl_easy_cleanup(curl); } return 0; } -
jglenn9k revised this gist
Mar 29, 2018 . No changes.There are no files selected for viewing
-
jglenn9k created this gist
Mar 29, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,77 @@ #include <iostream> #include <string> #include <cstdio> #include <curl/curl.h> static size_t WriteCallback(void *contents, size_t size, size_t nmemb, void *userp) { ((std::string*)userp)->append((char*)contents, size * nmemb); return size * nmemb; } int main(int argc, char **argv) { if (argc != 2) { std::cout << "ERROR - Must provide a URL." << std::endl; return 2; } CURL *curl; CURLcode res; std::string readBuffer; curl = curl_easy_init(); if(curl) { curl_easy_setopt(curl, CURLOPT_HEADER, false); curl_easy_setopt(curl, CURLOPT_ENCODING, "gzip"); curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); curl_easy_setopt(curl, CURLOPT_VERBOSE, false); curl_easy_setopt(curl, CURLOPT_USERAGENT, "Page Speed Checker v1.0"); curl_easy_setopt(curl, CURLOPT_URL, argv[1]); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer); res = curl_easy_perform(curl); if(CURLE_OK == res) { char *url = NULL; curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_URL, &url); long response_code; curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response_code); double dlsize; curl_easy_getinfo(curl, CURLINFO_SIZE_DOWNLOAD, &dlsize); double dlspeed; curl_easy_getinfo(curl, CURLINFO_SPEED_DOWNLOAD, &dlspeed); double namelookup; curl_easy_getinfo(curl, CURLINFO_NAMELOOKUP_TIME, &namelookup); double connect; curl_easy_getinfo(curl, CURLINFO_CONNECT_TIME, &connect); double pretransfer; curl_easy_getinfo(curl, CURLINFO_PRETRANSFER_TIME, &pretransfer); double start; curl_easy_getinfo(curl, CURLINFO_STARTTRANSFER_TIME, &start); double redirect; curl_easy_getinfo(curl, CURLINFO_REDIRECT_TIME, &redirect); double total; curl_easy_getinfo(curl, CURLINFO_TOTAL_TIME, &total); long redirects; curl_easy_getinfo(curl, CURLINFO_REDIRECT_COUNT, &redirects); if((CURLE_OK == res) && response_code) { printf("Redirected to: %s\n", url); printf("Response Code: %d\n", response_code); printf("Total Redirects: %d\n", redirects); printf("Downloaded: %.0f bytes\n", dlsize); printf("Download speed %.0f bytes/sec\n", dlspeed); printf("Name Lookup Time: %.2f\n", namelookup); printf("Connect Time: %.2f\n", connect); printf("Pretransfer Time: %.2f\n", pretransfer); printf("Start Time: %.2f\n", start); printf("Redirect Time: %.2f\n", redirect); printf("Total Time: %.2f\n", total); } } curl_easy_cleanup(curl); } return 0; }