# HG changeset patch # User František Kučera # Date 1647047024 -3600 # Node ID 602462d04c578046ee32facfe9d754c8ff77d0a5 # Parent 9c710397ced6aff42aa7410cdc0dd014c9157725 print somehow HTTP headers on STDERR diff -r 9c710397ced6 -r 602462d04c57 src/HTTPHandler.h --- a/src/HTTPHandler.h Sun Mar 06 22:01:32 2022 +0100 +++ b/src/HTTPHandler.h Sat Mar 12 02:03:44 2022 +0100 @@ -63,6 +63,17 @@ return r; } + void headersCallback(std::string value) { + // TODO: parse name=value and store for later use + std::cerr << std::endl << "HTTP response headers:" << std::endl << ">>>" << value << "<<<" << std::endl << "--------" << std::endl; + } + + static uint headersCurlCallback(char* buffer, size_t size, size_t nmemb, HTTPHandler* instance) { + size_t r = size * nmemb; + instance->headersCallback(std::string(buffer, r)); + return r; + } + public: HTTPHandler(shared_ptr relationalWriter, Configuration configuration) : relationalWriter(relationalWriter), configuration(configuration) { @@ -99,10 +110,17 @@ CURL* curl = curl_easy_init(); curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); + curl_easy_setopt(curl, CURLOPT_WRITEDATA, this); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writeCurlCallback); + + curl_easy_setopt(curl, CURLOPT_HEADERDATA, this); + curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, headersCurlCallback); + curl_easy_perform(curl); + curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &responseCode); + curl_easy_cleanup(curl); relationalWriter->writeAttribute(&responseCode, typeid (responseCode));