diff options
| author | Murilo Ijanc <[email protected]> | 2026-07-26 12:28:10 -0300 |
|---|---|---|
| committer | Murilo Ijanc <[email protected]> | 2026-07-26 12:28:10 -0300 |
| commit | b71faa6e95a0736f1ff171e006b171467b65db90 (patch) | |
| tree | 7580c3ab515e8f50726dc68dbc240995ff4a1a4c /src/http.hpp | |
| download | cpp-b71faa6e95a0736f1ff171e006b171467b65db90.tar.gz | |
Initial importv0.1.0
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 |