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
25
namespace
MetaImGUI
{
26
33
enum class
HttpStatus
{
34
Ok
,
35
RateLimited
,
36
NetworkError
,
37
Cancelled
38
};
39
40
struct
HttpResponse
{
41
HttpStatus
status
=
HttpStatus::NetworkError
;
42
long
httpCode
= 0;
43
std::string
body
;
44
};
45
46
struct
HttpRequest
{
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
65
class
HttpClient
{
66
public
:
67
HttpClient
() =
default
;
68
~HttpClient
() =
default
;
69
70
HttpClient
(
const
HttpClient
&) =
delete
;
71
HttpClient
&
operator=
(
const
HttpClient
&) =
delete
;
72
HttpClient
(
HttpClient
&&) =
default
;
73
HttpClient
&
operator=
(
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
88
private
:
89
[[nodiscard]]
HttpResponse
PerformOnce(
const
HttpRequest
& request,
const
std::stop_token& stopToken)
const
;
90
};
91
92
}
// namespace MetaImGUI
MetaImGUI::HttpClient
Thin RAII wrapper around libcurl_easy for application-side fetches.
Definition
HttpClient.h:65
MetaImGUI::HttpClient::~HttpClient
~HttpClient()=default
MetaImGUI::HttpClient::Get
HttpResponse Get(const HttpRequest &request, const std::stop_token &stopToken) const
Issue a GET request, honouring stop_token cancellation.
Definition
HttpClient.cpp:78
MetaImGUI::HttpClient::HttpClient
HttpClient(HttpClient &&)=default
MetaImGUI::HttpClient::operator=
HttpClient & operator=(const HttpClient &)=delete
MetaImGUI::HttpClient::HttpClient
HttpClient(const HttpClient &)=delete
MetaImGUI::HttpClient::HttpClient
HttpClient()=default
MetaImGUI::HttpClient::operator=
HttpClient & operator=(HttpClient &&)=default
MetaImGUI
Definition
Application.h:30
MetaImGUI::HttpStatus
HttpStatus
Result classification for an HTTP fetch.
Definition
HttpClient.h:33
MetaImGUI::HttpStatus::NetworkError
@ NetworkError
curl/transport failure, or non-2xx that isn't rate-limit
MetaImGUI::HttpStatus::RateLimited
@ RateLimited
403 with X-RateLimit-Remaining: 0 (GitHub-style)
MetaImGUI::HttpStatus::Cancelled
@ Cancelled
stop_token::stop_requested() fired during transfer
MetaImGUI::HttpStatus::Ok
@ Ok
2xx response, body populated
MetaImGUI::HttpRequest
Definition
HttpClient.h:46
MetaImGUI::HttpRequest::url
std::string url
Definition
HttpClient.h:47
MetaImGUI::HttpRequest::maxRetries
int maxRetries
Retries on transient network failure (not on rate-limit/cancel/4xx).
Definition
HttpClient.h:51
MetaImGUI::HttpRequest::followRedirects
bool followRedirects
Definition
HttpClient.h:50
MetaImGUI::HttpRequest::userAgent
std::string userAgent
Definition
HttpClient.h:48
MetaImGUI::HttpRequest::timeout
std::chrono::seconds timeout
Definition
HttpClient.h:49
MetaImGUI::HttpResponse
Definition
HttpClient.h:40
MetaImGUI::HttpResponse::status
HttpStatus status
Definition
HttpClient.h:41
MetaImGUI::HttpResponse::body
std::string body
Definition
HttpClient.h:43
MetaImGUI::HttpResponse::httpCode
long httpCode
Definition
HttpClient.h:42
include
HttpClient.h
Generated by
1.9.8