print somehow HTTP headers on STDERR v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Sat, 12 Mar 2022 02:03:44 +0100
branchv_0
changeset 4 602462d04c57
parent 3 9c710397ced6
child 5 165f6162524d
print somehow HTTP headers on STDERR
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<relpipe::writer::RelationalWriter> 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));