blob: 601a2d5c03aabcf13b20f9aa56fe3a8dbc4ca0e1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
#ifndef CEPIS_SRC_HTTP_HPP
#define CEPIS_SRC_HTTP_HPP
#include <chrono>
#include <string>
#include <string_view>
namespace cepis::detail {
/// What one attempt asked for.
struct HttpRequest {
std::string url;
std::string user_agent;
std::chrono::milliseconds timeout{0};
};
/// What one attempt got back.
///
/// `completed` separates "the server answered, here is its status" from "the
/// request never got there" — the two need different errors, and only the
/// second one has a `curl_error` worth showing.
struct HttpResult {
bool completed = false;
int status = 0;
std::string body;
std::string retry_after;
std::string curl_error;
};
/// Performs one GET. Never throws; failures arrive in `HttpResult`.
HttpResult perform_get(const HttpRequest& request);
/// Percent-encodes `value` for use in a query-string value, RFC 3986
/// unreserved set. A comma becomes `%2C`.
std::string url_escape(std::string_view value);
} // namespace cepis::detail
#endif // CEPIS_SRC_HTTP_HPP
|