aboutsummaryrefslogtreecommitdiff
path: root/src/zenhttp/include
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2023-05-15 20:41:57 +0200
committerStefan Boberg <[email protected]>2023-05-15 20:41:57 +0200
commitc0eabf9ce24274336d402737b2f8ea3d6772d33b (patch)
tree853dcee9fa1d4542fb5d18b17638a1cf0395024f /src/zenhttp/include
parentadded some top-level trace scopes to httpsys impl (diff)
downloadzen-c0eabf9ce24274336d402737b2f8ea3d6772d33b.tar.xz
zen-c0eabf9ce24274336d402737b2f8ea3d6772d33b.zip
some HttpClient changes eliminating some cpr helpers
Diffstat (limited to 'src/zenhttp/include')
-rw-r--r--src/zenhttp/include/zenhttp/httpclient.h30
1 files changed, 27 insertions, 3 deletions
diff --git a/src/zenhttp/include/zenhttp/httpclient.h b/src/zenhttp/include/zenhttp/httpclient.h
index 9f08835d3..559d7e719 100644
--- a/src/zenhttp/include/zenhttp/httpclient.h
+++ b/src/zenhttp/include/zenhttp/httpclient.h
@@ -8,6 +8,8 @@
#include <zencore/uid.h>
#include <zenhttp/httpcommon.h>
+#include <optional>
+
namespace zen {
class CbPackage;
@@ -15,6 +17,11 @@ class CbPackage;
/** HTTP client implementation for Zen use cases
Currently simple and synchronous, should become lean and asynchronous
+
+ This does not attempt to provide an interface which can be used to interface
+ with arbitrary services, it's primarily intended for interfacing with UE
+ development ecosystem HTTP services like Zen store or Jupiter
+
*/
class HttpClient
@@ -23,12 +30,27 @@ public:
HttpClient(std::string_view BaseUri);
~HttpClient();
+ struct ErrorContext
+ {
+ std::string ErrorMessage;
+ };
+
struct Response
{
HttpResponseCode StatusCode = HttpResponseCode::ImATeapot;
IoBuffer ResponsePayload; // Note: this also includes the content type
- CbObject AsObject();
+ // This contains any errors from the HTTP stack. It won't contain information on
+ // why the server responded with a non-success HTTP status, that may be gleaned
+ // from the response payload itself depending on what the server provides.
+ std::optional<ErrorContext> Error;
+
+ // Return the response payload as a CbObject. Note that this does not attempt to
+ // validate that the content type or content itself makes sense as a CbObject
+ CbObject AsObject();
+
+ // Return the response payload as a CbPackage. Note that this does not attempt to
+ // validate that the content type or content itself makes sense as a CbPackage
CbPackage AsPackage();
// Return the response payload as a string. Note that this does not attempt to
@@ -39,8 +61,10 @@ public:
// objects, returns text as-is for text types like Text, JSON, HTML etc
std::string ToText();
- bool IsSuccess() const noexcept;
- inline operator bool() const noexcept { return IsSuccess(); }
+ // Returns whether the HTTP status code is considered successful (i.e in the
+ // 2xx range)
+ bool IsSuccess() const noexcept;
+ inline explicit operator bool() const noexcept { return IsSuccess(); }
};
[[nodiscard]] Response Put(std::string_view Url, const IoBuffer& Payload);