61 size_t r = size * nmemb; |
61 size_t r = size * nmemb; |
62 instance->writeCallback(std::string(buffer, r)); |
62 instance->writeCallback(std::string(buffer, r)); |
63 return r; |
63 return r; |
64 } |
64 } |
65 |
65 |
|
66 void headersCallback(std::string value) { |
|
67 // TODO: parse name=value and store for later use |
|
68 std::cerr << std::endl << "HTTP response headers:" << std::endl << ">>>" << value << "<<<" << std::endl << "--------" << std::endl; |
|
69 } |
|
70 |
|
71 static uint headersCurlCallback(char* buffer, size_t size, size_t nmemb, HTTPHandler* instance) { |
|
72 size_t r = size * nmemb; |
|
73 instance->headersCallback(std::string(buffer, r)); |
|
74 return r; |
|
75 } |
|
76 |
66 public: |
77 public: |
67 |
78 |
68 HTTPHandler(shared_ptr<relpipe::writer::RelationalWriter> relationalWriter, Configuration configuration) : relationalWriter(relationalWriter), configuration(configuration) { |
79 HTTPHandler(shared_ptr<relpipe::writer::RelationalWriter> relationalWriter, Configuration configuration) : relationalWriter(relationalWriter), configuration(configuration) { |
69 } |
80 } |
70 |
81 |
97 std::string url = convertor.to_bytes(value); |
108 std::string url = convertor.to_bytes(value); |
98 relpipe::common::type::Integer responseCode = 0; |
109 relpipe::common::type::Integer responseCode = 0; |
99 |
110 |
100 CURL* curl = curl_easy_init(); |
111 CURL* curl = curl_easy_init(); |
101 curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); |
112 curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); |
|
113 |
102 curl_easy_setopt(curl, CURLOPT_WRITEDATA, this); |
114 curl_easy_setopt(curl, CURLOPT_WRITEDATA, this); |
103 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writeCurlCallback); |
115 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writeCurlCallback); |
|
116 |
|
117 curl_easy_setopt(curl, CURLOPT_HEADERDATA, this); |
|
118 curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, headersCurlCallback); |
|
119 |
104 curl_easy_perform(curl); |
120 curl_easy_perform(curl); |
|
121 |
105 curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &responseCode); |
122 curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &responseCode); |
|
123 |
106 curl_easy_cleanup(curl); |
124 curl_easy_cleanup(curl); |
107 |
125 |
108 relationalWriter->writeAttribute(&responseCode, typeid (responseCode)); |
126 relationalWriter->writeAttribute(&responseCode, typeid (responseCode)); |
109 } |
127 } |
110 |
128 |