MetaImGUI 1.0.0
ImGui Application Template for C++20
Loading...
Searching...
No Matches
HttpClient.h
Go to the documentation of this file.
1/*
2 MetaImGUI
3 Copyright (C) 2026 A P Nicholson
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>.
17*/
18
19#pragma once
20
21#include <chrono>
22#include <stop_token>
23#include <string>
24
25namespace MetaImGUI {
26
33enum class HttpStatus {
34 Ok,
38};
39
45
47 std::string url;
48 std::string userAgent = "MetaImGUI/1.0";
49 std::chrono::seconds timeout{10};
50 bool followRedirects = true;
51 int maxRetries = 0;
52};
53
66public:
67 HttpClient() = default;
68 ~HttpClient() = default;
69
70 HttpClient(const HttpClient&) = delete;
71 HttpClient& operator=(const HttpClient&) = delete;
72 HttpClient(HttpClient&&) = default;
74
83 [[nodiscard]] HttpResponse Get(const HttpRequest& request, const std::stop_token& stopToken) const;
84
86 [[nodiscard]] HttpResponse Get(const HttpRequest& request) const;
87
88private:
89 [[nodiscard]] HttpResponse PerformOnce(const HttpRequest& request, const std::stop_token& stopToken) const;
90};
91
92} // namespace MetaImGUI
Thin RAII wrapper around libcurl_easy for application-side fetches.
Definition HttpClient.h:65
HttpResponse Get(const HttpRequest &request, const std::stop_token &stopToken) const
Issue a GET request, honouring stop_token cancellation.
HttpClient(HttpClient &&)=default
HttpClient & operator=(const HttpClient &)=delete
HttpClient(const HttpClient &)=delete
HttpClient & operator=(HttpClient &&)=default
HttpStatus
Result classification for an HTTP fetch.
Definition HttpClient.h:33
@ NetworkError
curl/transport failure, or non-2xx that isn't rate-limit
@ RateLimited
403 with X-RateLimit-Remaining: 0 (GitHub-style)
@ Cancelled
stop_token::stop_requested() fired during transfer
@ Ok
2xx response, body populated
int maxRetries
Retries on transient network failure (not on rate-limit/cancel/4xx).
Definition HttpClient.h:51
std::string userAgent
Definition HttpClient.h:48
std::chrono::seconds timeout
Definition HttpClient.h:49