ChatPlexSDK-BS 1.0.1-v6.2.0
C++ ChatPlex BeatSaber SDK
Loading...
Searching...
No Matches
WebClientUnity.hpp
1#pragma once
2
3#include "IWebClient.hpp"
4
5#include <custom-types/shared/coroutine.hpp>
6#include <System/TimeSpan.hpp>
7
8#include <map>
9#include <mutex>
10
11namespace CP_SDK::Network {
12
13 namespace _u
14 {
15 using namespace System;
16 using namespace System::Threading;
17 using namespace UnityEngine::Networking;
18 }
19 namespace _v
20 {
21 using namespace CP_SDK::Utils;
22 }
23
25 class WebClientUnity : public IWebClient, public std::enable_shared_from_this<WebClientUnity>
26 {
27 CP_SDK_NO_COPYMOVE_CTORS(WebClientUnity);
28 CP_SDK_PRIV_TAG();
29
30 public:
31 using Ptr = std::shared_ptr<WebClientUnity>;
32
33 private:
34 static Ptr m_GlobalClient;
35
36 public:
39
40 private:
41 std::u16string m_BaseAddress;
42 int m_Timeout;
43 std::map<std::u16string, std::u16string> m_Headers;
44 std::mutex m_HeadersLock;
45
46 public:
53
54 public:
59 WebClientUnity(CP_SDK_PRIV_TAG_ARG(), std::u16string_view p_BaseAddress, _u::TimeSpan p_TimeOut, bool p_ForceCacheDiscard);
60
65 static Ptr Make(std::u16string_view p_BaseAddress, _u::TimeSpan p_TimeOut, bool p_ForceCacheDiscard = false);
66
67 public:
70 virtual std::u16string GetHeader(std::u16string_view p_Name) override final;
74 virtual void SetHeader(std::u16string_view p_Name, std::u16string_view p_Value) override final;
77 virtual void RemoveHeader(std::u16string_view p_Name) override final;
78
79 public:
86 virtual void GetAsync(std::u16string_view p_URL, _u::CancellationToken p_Token, _v::CActionRef<WebResponse::Ptr> p_Callback, bool p_DontRetry = false, _v::CActionRef<float> p_Progress = nullptr) override final;
93 virtual void DownloadAsync(std::u16string_view p_URL, _u::CancellationToken p_Token, _v::CActionRef<WebResponse::Ptr> p_Callback, bool p_DontRetry = false, _v::CActionRef<float> p_Progress = nullptr) override final;
100 virtual void PostAsync(std::u16string_view p_URL, const WebContent::Ptr& p_Content, _u::CancellationToken p_Token, _v::CActionRef<WebResponse::Ptr> p_Callback, bool p_DontRetry = false) override final;
107 virtual void PatchAsync(std::u16string_view p_URL, const WebContent::Ptr& p_Content, _u::CancellationToken p_Token, _v::CActionRef<WebResponse::Ptr> p_Callback, bool p_DontRetry = false) override final;
113 virtual void DeleteAsync(std::u16string_view p_URL, _u::CancellationToken p_Token, _v::CActionRef<WebResponse::Ptr> p_Callback, bool p_DontRetry = false) override final;
114
115 private:
118 std::u16string GetURL(std::u16string_view p_URL);
121 std::u16string SafeURL(std::u16string_view p_URL);
122
123 private:
127 void PrepareRequest(_u::UnityWebRequest* p_Request, bool p_IsDownload);
137 static custom_types::Helpers::Coroutine Coroutine_DoRequest(Ptr p_Self,
138 std::u16string p_DebugName,
139 std::u16string p_HttpMethod,
140 std::u16string p_URL,
141 WebContent::Ptr p_Content,
142 _u::CancellationToken p_Token,
143 _v::Action<WebResponse::Ptr> p_Callback,
144 bool p_DontRetry,
145 _v::Action<float> p_Progress);
146
147 };
148
149}
Web Client interface.
WebClientUnity using unity web requests.
int MaxRetry
Maximum retry attempt.
virtual std::u16string GetHeader(std::u16string_view p_Name) override final
Get header.
virtual void SetHeader(std::u16string_view p_Name, std::u16string_view p_Value) override final
Set header.
virtual void DeleteAsync(std::u16string_view p_URL, _u::CancellationToken p_Token, _v::CActionRef< WebResponse::Ptr > p_Callback, bool p_DontRetry=false) override final
Do Async DELETE query.
static Ptr Make(std::u16string_view p_BaseAddress, _u::TimeSpan p_TimeOut, bool p_ForceCacheDiscard=false)
Constructor.
static WebClientUnity * GlobalClient()
Global client instance.
virtual void GetAsync(std::u16string_view p_URL, _u::CancellationToken p_Token, _v::CActionRef< WebResponse::Ptr > p_Callback, bool p_DontRetry=false, _v::CActionRef< float > p_Progress=nullptr) override final
Do Async GET query.
int DownloadTimeout
Timeout seconds.
virtual void PostAsync(std::u16string_view p_URL, const WebContent::Ptr &p_Content, _u::CancellationToken p_Token, _v::CActionRef< WebResponse::Ptr > p_Callback, bool p_DontRetry=false) override final
Do Async POST query.
virtual void PatchAsync(std::u16string_view p_URL, const WebContent::Ptr &p_Content, _u::CancellationToken p_Token, _v::CActionRef< WebResponse::Ptr > p_Callback, bool p_DontRetry=false) override final
Do Async PATCH query.
virtual void RemoveHeader(std::u16string_view p_Name) override final
Remove header.
int RetryInterval
Delay between each retry.
WebClientUnity(CP_SDK_PRIV_TAG_ARG(), std::u16string_view p_BaseAddress, _u::TimeSpan p_TimeOut, bool p_ForceCacheDiscard)
Constructor.
virtual void DownloadAsync(std::u16string_view p_URL, _u::CancellationToken p_Token, _v::CActionRef< WebResponse::Ptr > p_Callback, bool p_DontRetry=false, _v::CActionRef< float > p_Progress=nullptr) override final
Do Async GET query.
Network and HTTP utilities.
Various platform utils like Delegate/Action/Function/Event system.
Definition Delegate.hpp:8