src/HTTPClient.cpp
author František Kučera <franta-hg@frantovo.cz>
Tue, 15 Mar 2022 23:29:36 +0100
branchv_0
changeset 10 479557122717
parent 9 9fdbfbe24161
child 11 6b913e82f52a
permissions -rw-r--r--
initialize the CURL callbacks only once in the open() function
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5
165f6162524d introduce HTTPClient wrapper around CURL
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     1
/**
165f6162524d introduce HTTPClient wrapper around CURL
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     2
 * Relational pipes
165f6162524d introduce HTTPClient wrapper around CURL
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     3
 * Copyright © 2022 František Kučera (Frantovo.cz, GlobalCode.info)
165f6162524d introduce HTTPClient wrapper around CURL
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     4
 *
165f6162524d introduce HTTPClient wrapper around CURL
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     5
 * This program is free software: you can redistribute it and/or modify
165f6162524d introduce HTTPClient wrapper around CURL
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
165f6162524d introduce HTTPClient wrapper around CURL
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     7
 * the Free Software Foundation, version 3 of the License.
165f6162524d introduce HTTPClient wrapper around CURL
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     8
 *
165f6162524d introduce HTTPClient wrapper around CURL
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
165f6162524d introduce HTTPClient wrapper around CURL
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
165f6162524d introduce HTTPClient wrapper around CURL
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
165f6162524d introduce HTTPClient wrapper around CURL
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    12
 * GNU General Public License for more details.
165f6162524d introduce HTTPClient wrapper around CURL
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    13
 *
165f6162524d introduce HTTPClient wrapper around CURL
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
165f6162524d introduce HTTPClient wrapper around CURL
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    15
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
165f6162524d introduce HTTPClient wrapper around CURL
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    16
 */
165f6162524d introduce HTTPClient wrapper around CURL
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    17
165f6162524d introduce HTTPClient wrapper around CURL
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    18
#include <sstream>
6
59c9ca066322 write response headers as a relation
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    19
#include <iostream>
5
165f6162524d introduce HTTPClient wrapper around CURL
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    20
165f6162524d introduce HTTPClient wrapper around CURL
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    21
#include <curl/curl.h>
165f6162524d introduce HTTPClient wrapper around CURL
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    22
165f6162524d introduce HTTPClient wrapper around CURL
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    23
#include "HTTPClient.h"
165f6162524d introduce HTTPClient wrapper around CURL
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    24
165f6162524d introduce HTTPClient wrapper around CURL
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    25
165f6162524d introduce HTTPClient wrapper around CURL
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    26
namespace relpipe {
165f6162524d introduce HTTPClient wrapper around CURL
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    27
namespace tr {
165f6162524d introduce HTTPClient wrapper around CURL
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    28
namespace http {
165f6162524d introduce HTTPClient wrapper around CURL
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    29
165f6162524d introduce HTTPClient wrapper around CURL
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    30
class HTTPClient::HTTPClientImpl {
165f6162524d introduce HTTPClient wrapper around CURL
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    31
public:
165f6162524d introduce HTTPClient wrapper around CURL
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    32
	CURL* curl;
165f6162524d introduce HTTPClient wrapper around CURL
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    33
	std::stringstream responseBody;
6
59c9ca066322 write response headers as a relation
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    34
	std::stringstream responseHeaders;
5
165f6162524d introduce HTTPClient wrapper around CURL
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    35
165f6162524d introduce HTTPClient wrapper around CURL
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    36
	HTTPClientImpl(CURL* curl) : curl(curl) {
165f6162524d introduce HTTPClient wrapper around CURL
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    37
	}
165f6162524d introduce HTTPClient wrapper around CURL
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    38
6
59c9ca066322 write response headers as a relation
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    39
	std::vector<std::string> getResponseHeaders() {
59c9ca066322 write response headers as a relation
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    40
		std::vector<std::string> heathers;
59c9ca066322 write response headers as a relation
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    41
		std::stringstream name;
59c9ca066322 write response headers as a relation
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    42
		std::stringstream value;
59c9ca066322 write response headers as a relation
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    43
		std::stringstream* current = &name;
59c9ca066322 write response headers as a relation
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    44
		for (char ch = responseHeaders.get(); responseHeaders.good(); ch = responseHeaders.get()) {
59c9ca066322 write response headers as a relation
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    45
			if (ch == ':') {
59c9ca066322 write response headers as a relation
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    46
				current = &value;
59c9ca066322 write response headers as a relation
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    47
				for (char space = responseHeaders.get(); responseHeaders.good() && responseHeaders.peek() == ' '; space = responseHeaders.get()); // skip spaces
59c9ca066322 write response headers as a relation
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    48
			} else if (ch == '\n') {
59c9ca066322 write response headers as a relation
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    49
				if (name.tellp() > 0 && current == &value) {
59c9ca066322 write response headers as a relation
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    50
					heathers.push_back(name.str());
59c9ca066322 write response headers as a relation
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    51
					heathers.push_back(value.str());
59c9ca066322 write response headers as a relation
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    52
				} else if (name.tellp() > 0 && current == &value) {
59c9ca066322 write response headers as a relation
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    53
					// TODO: usually "HTTP/1.1 200 OK" → extract HTTP version and message?
59c9ca066322 write response headers as a relation
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    54
				}
59c9ca066322 write response headers as a relation
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    55
59c9ca066322 write response headers as a relation
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    56
				name = std::stringstream();
59c9ca066322 write response headers as a relation
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    57
				value = std::stringstream();
59c9ca066322 write response headers as a relation
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    58
				current = &name;
59c9ca066322 write response headers as a relation
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    59
			} else if (ch == '\r') {
59c9ca066322 write response headers as a relation
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    60
				// ignore
59c9ca066322 write response headers as a relation
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    61
			} else {
59c9ca066322 write response headers as a relation
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    62
				current->put(ch);
59c9ca066322 write response headers as a relation
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    63
			}
59c9ca066322 write response headers as a relation
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    64
		}
59c9ca066322 write response headers as a relation
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    65
		return heathers;
5
165f6162524d introduce HTTPClient wrapper around CURL
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    66
	}
165f6162524d introduce HTTPClient wrapper around CURL
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    67
165f6162524d introduce HTTPClient wrapper around CURL
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    68
};
165f6162524d introduce HTTPClient wrapper around CURL
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    69
7
0b0374746e48 request headers support in HTTPClient
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    70
class CurlList {
0b0374746e48 request headers support in HTTPClient
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    71
private:
0b0374746e48 request headers support in HTTPClient
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    72
	curl_slist* list = nullptr;
0b0374746e48 request headers support in HTTPClient
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    73
public:
0b0374746e48 request headers support in HTTPClient
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    74
	CurlList() = default;
0b0374746e48 request headers support in HTTPClient
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    75
	CurlList(const HTTPClient&) = delete;
0b0374746e48 request headers support in HTTPClient
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    76
	CurlList& operator=(const CurlList&) = delete;
0b0374746e48 request headers support in HTTPClient
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    77
0b0374746e48 request headers support in HTTPClient
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    78
	virtual ~CurlList() {
0b0374746e48 request headers support in HTTPClient
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    79
		curl_slist_free_all(list);
0b0374746e48 request headers support in HTTPClient
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    80
	}
0b0374746e48 request headers support in HTTPClient
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    81
0b0374746e48 request headers support in HTTPClient
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    82
	void append(std::string item) {
0b0374746e48 request headers support in HTTPClient
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    83
		list = curl_slist_append(list, item.c_str());
0b0374746e48 request headers support in HTTPClient
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    84
	}
0b0374746e48 request headers support in HTTPClient
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    85
0b0374746e48 request headers support in HTTPClient
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    86
	curl_slist* getList() {
0b0374746e48 request headers support in HTTPClient
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    87
		return list;
0b0374746e48 request headers support in HTTPClient
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    88
	}
0b0374746e48 request headers support in HTTPClient
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    89
};
0b0374746e48 request headers support in HTTPClient
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    90
5
165f6162524d introduce HTTPClient wrapper around CURL
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    91
HTTPClient* HTTPClient::open() {
10
479557122717 initialize the CURL callbacks only once in the open() function
František Kučera <franta-hg@frantovo.cz>
parents: 9
diff changeset
    92
	HTTPClient::HTTPClientImpl* impl = new HTTPClient::HTTPClientImpl(curl_easy_init());
479557122717 initialize the CURL callbacks only once in the open() function
František Kučera <franta-hg@frantovo.cz>
parents: 9
diff changeset
    93
479557122717 initialize the CURL callbacks only once in the open() function
František Kučera <franta-hg@frantovo.cz>
parents: 9
diff changeset
    94
	typedef size_t(*CurlWriteCallback)(char*, size_t, size_t, HTTPClient::HTTPClientImpl*);
479557122717 initialize the CURL callbacks only once in the open() function
František Kučera <franta-hg@frantovo.cz>
parents: 9
diff changeset
    95
479557122717 initialize the CURL callbacks only once in the open() function
František Kučera <franta-hg@frantovo.cz>
parents: 9
diff changeset
    96
	// set response body callback
479557122717 initialize the CURL callbacks only once in the open() function
František Kučera <franta-hg@frantovo.cz>
parents: 9
diff changeset
    97
	curl_easy_setopt(impl->curl, CURLOPT_WRITEDATA, impl);
479557122717 initialize the CURL callbacks only once in the open() function
František Kučera <franta-hg@frantovo.cz>
parents: 9
diff changeset
    98
	curl_easy_setopt(impl->curl, CURLOPT_WRITEFUNCTION, (CurlWriteCallback)[](char* buffer, size_t size, size_t nmemb, HTTPClient::HTTPClientImpl * impl)->size_t {
479557122717 initialize the CURL callbacks only once in the open() function
František Kučera <franta-hg@frantovo.cz>
parents: 9
diff changeset
    99
		size_t r = size * nmemb;
479557122717 initialize the CURL callbacks only once in the open() function
František Kučera <franta-hg@frantovo.cz>
parents: 9
diff changeset
   100
		impl->responseBody.write(buffer, r);
479557122717 initialize the CURL callbacks only once in the open() function
František Kučera <franta-hg@frantovo.cz>
parents: 9
diff changeset
   101
		return r;
479557122717 initialize the CURL callbacks only once in the open() function
František Kučera <franta-hg@frantovo.cz>
parents: 9
diff changeset
   102
	});
479557122717 initialize the CURL callbacks only once in the open() function
František Kučera <franta-hg@frantovo.cz>
parents: 9
diff changeset
   103
479557122717 initialize the CURL callbacks only once in the open() function
František Kučera <franta-hg@frantovo.cz>
parents: 9
diff changeset
   104
	// set response headers callback
479557122717 initialize the CURL callbacks only once in the open() function
František Kučera <franta-hg@frantovo.cz>
parents: 9
diff changeset
   105
	curl_easy_setopt(impl->curl, CURLOPT_HEADERDATA, impl);
479557122717 initialize the CURL callbacks only once in the open() function
František Kučera <franta-hg@frantovo.cz>
parents: 9
diff changeset
   106
	curl_easy_setopt(impl->curl, CURLOPT_HEADERFUNCTION, (CurlWriteCallback)[](char* buffer, size_t size, size_t nmemb, HTTPClient::HTTPClientImpl * impl)->size_t {
479557122717 initialize the CURL callbacks only once in the open() function
František Kučera <franta-hg@frantovo.cz>
parents: 9
diff changeset
   107
		size_t r = size * nmemb;
479557122717 initialize the CURL callbacks only once in the open() function
František Kučera <franta-hg@frantovo.cz>
parents: 9
diff changeset
   108
		impl->responseHeaders.write(buffer, r);
479557122717 initialize the CURL callbacks only once in the open() function
František Kučera <franta-hg@frantovo.cz>
parents: 9
diff changeset
   109
		return r;
479557122717 initialize the CURL callbacks only once in the open() function
František Kučera <franta-hg@frantovo.cz>
parents: 9
diff changeset
   110
	});
479557122717 initialize the CURL callbacks only once in the open() function
František Kučera <franta-hg@frantovo.cz>
parents: 9
diff changeset
   111
479557122717 initialize the CURL callbacks only once in the open() function
František Kučera <franta-hg@frantovo.cz>
parents: 9
diff changeset
   112
	return new HTTPClient(impl);
5
165f6162524d introduce HTTPClient wrapper around CURL
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   113
}
165f6162524d introduce HTTPClient wrapper around CURL
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   114
165f6162524d introduce HTTPClient wrapper around CURL
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   115
HTTPClient::~HTTPClient() {
165f6162524d introduce HTTPClient wrapper around CURL
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   116
	curl_easy_cleanup(impl->curl);
165f6162524d introduce HTTPClient wrapper around CURL
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   117
	delete impl;
165f6162524d introduce HTTPClient wrapper around CURL
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   118
}
165f6162524d introduce HTTPClient wrapper around CURL
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   119
165f6162524d introduce HTTPClient wrapper around CURL
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   120
const HTTPClient::Response HTTPClient::exchange(const Request& request) {
165f6162524d introduce HTTPClient wrapper around CURL
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   121
	HTTPClient::Response response;
165f6162524d introduce HTTPClient wrapper around CURL
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   122
165f6162524d introduce HTTPClient wrapper around CURL
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   123
	// TODO: set request method
165f6162524d introduce HTTPClient wrapper around CURL
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   124
7
0b0374746e48 request headers support in HTTPClient
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
   125
	// set URL
5
165f6162524d introduce HTTPClient wrapper around CURL
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   126
	curl_easy_setopt(impl->curl, CURLOPT_URL, request.url.c_str());
9
9fdbfbe24161 throw and report exception on error (e.g. 'Couldn't connect to server')
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
   127
7
0b0374746e48 request headers support in HTTPClient
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
   128
	// set request headers
0b0374746e48 request headers support in HTTPClient
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
   129
	CurlList requestHeders;
0b0374746e48 request headers support in HTTPClient
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
   130
	for (size_t i = 0; i < request.headers.size(); i += 2) requestHeders.append(request.headers[i] + ": " + request.headers[i + 1]); // TODO: validate, no CR/LF...
0b0374746e48 request headers support in HTTPClient
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
   131
	curl_easy_setopt(impl->curl, CURLOPT_HTTPHEADER, requestHeders.getList());
5
165f6162524d introduce HTTPClient wrapper around CURL
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   132
7
0b0374746e48 request headers support in HTTPClient
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
   133
	// do HTTP call
9
9fdbfbe24161 throw and report exception on error (e.g. 'Couldn't connect to server')
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
   134
	CURLcode result = curl_easy_perform(impl->curl);
9fdbfbe24161 throw and report exception on error (e.g. 'Couldn't connect to server')
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
   135
9fdbfbe24161 throw and report exception on error (e.g. 'Couldn't connect to server')
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
   136
	if (result == CURLE_OK) {
5
165f6162524d introduce HTTPClient wrapper around CURL
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   137
9
9fdbfbe24161 throw and report exception on error (e.g. 'Couldn't connect to server')
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
   138
		// response code and fill the result object
9fdbfbe24161 throw and report exception on error (e.g. 'Couldn't connect to server')
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
   139
		curl_easy_getinfo(impl->curl, CURLINFO_RESPONSE_CODE, &response.responseCode);
9fdbfbe24161 throw and report exception on error (e.g. 'Couldn't connect to server')
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
   140
		response.headers = impl->getResponseHeaders();
9fdbfbe24161 throw and report exception on error (e.g. 'Couldn't connect to server')
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
   141
		response.body = impl->responseBody.str();
9fdbfbe24161 throw and report exception on error (e.g. 'Couldn't connect to server')
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
   142
		impl->responseBody = std::stringstream();
5
165f6162524d introduce HTTPClient wrapper around CURL
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   143
9
9fdbfbe24161 throw and report exception on error (e.g. 'Couldn't connect to server')
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
   144
		return response;
9fdbfbe24161 throw and report exception on error (e.g. 'Couldn't connect to server')
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
   145
	} else {
9fdbfbe24161 throw and report exception on error (e.g. 'Couldn't connect to server')
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
   146
		throw Exception(curl_easy_strerror(result));
9fdbfbe24161 throw and report exception on error (e.g. 'Couldn't connect to server')
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
   147
	}
5
165f6162524d introduce HTTPClient wrapper around CURL
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   148
}
165f6162524d introduce HTTPClient wrapper around CURL
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   149
165f6162524d introduce HTTPClient wrapper around CURL
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   150
165f6162524d introduce HTTPClient wrapper around CURL
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   151
}
165f6162524d introduce HTTPClient wrapper around CURL
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   152
}
165f6162524d introduce HTTPClient wrapper around CURL
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   153
}