-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIDekiHttpClient.h
More file actions
72 lines (65 loc) · 2.6 KB
/
Copy pathIDekiHttpClient.h
File metadata and controls
72 lines (65 loc) · 2.6 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#pragma once
#include <cstdint> // uint32_t in the Get/PostJson signatures below
#include <string>
#include <vector>
#include <utility>
/**
* @brief Abstract HTTP client interface.
*
* Concrete implementations live in platform integration modules and register
* themselves with DekiHttp at boot. Consumers fetch the active client via
* DekiHttp and call into the methods below; they never include any concrete
* client header.
*
* Failure modes are uniform across implementations:
* - Network / DNS / TLS errors → Response.status == -1, body empty.
* - Non-2xx → Response.status carries the code, body may be empty or
* contain the server's error payload.
* Implementations log details on failure.
*/
class IDekiHttpClient
{
public:
virtual ~IDekiHttpClient() = default;
struct Response {
int status = -1; // HTTP status, or -1 on transport error
std::string body; // response body (may be empty on failure)
};
using HeaderList = std::vector<std::pair<std::string, std::string>>;
/**
* @brief Legacy synchronous GET. Returns the response body as a string.
* Returns an empty string on any failure (transport, non-2xx, etc.).
* Kept for backward compatibility with existing call sites.
*/
virtual std::string FetchUrl(const std::string& url) = 0;
/**
* @brief Synchronous GET with custom request headers.
* Default implementation falls back to FetchUrl() and returns the
* body without status info; overriding gives status + body + header
* support. Implementations on real HTTP stacks override this.
*/
virtual Response Get(const std::string& url,
const HeaderList& headers = {},
uint32_t timeoutMs = 15000)
{
(void)headers; (void)timeoutMs;
Response r;
r.body = FetchUrl(url);
r.status = r.body.empty() ? -1 : 200;
return r;
}
/**
* @brief Synchronous POST with JSON body. Implementations set
* Content-Type: application/json automatically. Default returns
* a transport error so stubs / legacy clients that don't override
* fail loudly rather than silently succeeding.
*/
virtual Response PostJson(const std::string& url,
const std::string& body,
const HeaderList& headers = {},
uint32_t timeoutMs = 15000)
{
(void)url; (void)body; (void)headers; (void)timeoutMs;
return {};
}
};