equal
deleted
inserted
replaced
13 * |
13 * |
14 * You should have received a copy of the GNU General Public License |
14 * You should have received a copy of the GNU General Public License |
15 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
15 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 */ |
16 */ |
17 |
17 |
|
18 #include <string> |
18 #include <sstream> |
19 #include <sstream> |
19 #include <iostream> |
20 #include <iostream> |
20 |
21 |
21 #include <curl/curl.h> |
22 #include <curl/curl.h> |
22 |
23 |
128 } |
129 } |
129 |
130 |
130 const HTTPClient::Response HTTPClient::exchange(const Request& request) { |
131 const HTTPClient::Response HTTPClient::exchange(const Request& request) { |
131 HTTPClient::Response response; |
132 HTTPClient::Response response; |
132 |
133 |
133 // TODO: set request method |
134 // set request method |
|
135 std::string method; |
|
136 if (request.method == Method::DELETE) method = "DELETE"; |
|
137 else if (request.method == Method::GET) method = "GET"; |
|
138 else if (request.method == Method::HEAD) method = "HEAD"; |
|
139 else if (request.method == Method::PATCH) method = "PATCH"; |
|
140 else if (request.method == Method::POST) method = "POST"; |
|
141 else if (request.method == Method::PUT) method = "PUT"; |
|
142 else throw std::invalid_argument("Unsupported HTTP method: " + std::to_string((int) request.method)); |
|
143 curl_easy_setopt(impl->curl, CURLOPT_CUSTOMREQUEST, method.c_str()); |
|
144 if (request.method == Method::HEAD) curl_easy_setopt(impl->curl, CURLOPT_NOBODY, 1L); |
134 |
145 |
135 // set URL |
146 // set URL |
136 curl_easy_setopt(impl->curl, CURLOPT_URL, request.url.c_str()); |
147 curl_easy_setopt(impl->curl, CURLOPT_URL, request.url.c_str()); |
137 |
148 |
138 // set request headers |
149 // set request headers |