Compare commits

...

6 commits

Author SHA1 Message Date
Justin
3dd01ab804
Merge cded0523a5 into 1b5ae86f7b 2024-08-13 08:59:46 -04:00
HJfod
1b5ae86f7b fix s_idCounter missing definition 2024-08-13 13:42:24 +03:00
HJfod
1f2aa2ced7 how did i not notice- 2024-08-13 13:37:41 +03:00
HJfod
00e191accb
Merge pull request #1040 from SMJSGaming/main
Added IDs to web request to prevent incompatibilities between web mods
2024-08-13 11:35:49 +03:00
SMJSGaming
58402e9b7b Made the ID system thread safe 2024-08-13 10:11:54 +02:00
SMJSGaming
a5bbf6a40c Added IDs to web request to prevent incompatibilities between web mods 2024-08-13 09:05:59 +02:00
2 changed files with 18 additions and 1 deletions

View file

@ -113,7 +113,6 @@ namespace geode::utils::web {
class Impl;
std::shared_ptr<Impl> m_impl;
public:
WebRequest();
~WebRequest();
@ -253,6 +252,13 @@ namespace geode::utils::web {
*/
WebRequest& bodyJSON(matjson::Value const& json);
/**
* Gets the unique request ID
*
* @return size_t
*/
size_t getID() const;
/**
* Gets the request method as a string

View file

@ -188,6 +188,8 @@ std::optional<float> WebProgress::uploadProgress() const {
class WebRequest::Impl {
public:
static std::atomic_size_t s_idCounter;
std::string m_method;
std::string m_url;
std::unordered_map<std::string, std::string> m_headers;
@ -203,6 +205,9 @@ public:
std::string m_CABundleContent;
ProxyOpts m_proxyOpts = {};
HttpVersion m_httpVersion = HttpVersion::DEFAULT;
size_t m_id;
Impl() : m_id(s_idCounter++) {}
WebResponse makeError(int code, std::string const& msg) {
auto res = WebResponse();
@ -212,6 +217,8 @@ public:
}
};
std::atomic_size_t WebRequest::Impl::s_idCounter = 0;
WebRequest::WebRequest() : m_impl(std::make_shared<Impl>()) {}
WebRequest::~WebRequest() {}
@ -584,6 +591,10 @@ WebRequest& WebRequest::bodyJSON(matjson::Value const& json) {
return *this;
}
size_t WebRequest::getID() const {
return m_impl->m_id;
}
std::string WebRequest::getMethod() const {
return m_impl->m_method;
}