diff options
Diffstat (limited to 'src/http.hpp')
| -rw-r--r-- | src/http.hpp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/http.hpp b/src/http.hpp new file mode 100644 index 0000000..601a2d5 --- /dev/null +++ b/src/http.hpp @@ -0,0 +1,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 |