From 520a76a15ef9a0d8b854ad19d6dd42610769ecc4 Mon Sep 17 00:00:00 2001 From: RaidMax Date: Thu, 13 Apr 2023 21:36:21 -0500 Subject: [PATCH] add additional overloads for script plugin web request helper --- .../Plugin/Script/ScriptPluginHelper.cs | 20 +++++++++++++++---- Application/Plugin/Script/ScriptPluginV2.cs | 2 +- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/Application/Plugin/Script/ScriptPluginHelper.cs b/Application/Plugin/Script/ScriptPluginHelper.cs index 8af4e8748..528c1f820 100644 --- a/Application/Plugin/Script/ScriptPluginHelper.cs +++ b/Application/Plugin/Script/ScriptPluginHelper.cs @@ -28,16 +28,29 @@ public class ScriptPluginHelper RequestUrl(new ScriptPluginWebRequest(url), callback); } + public void GetUrl(string url, string bearerToken, Delegate callback) + { + var headers = new Dictionary { { "Authorization", $"Bearer {bearerToken}" } }; + RequestUrl(new ScriptPluginWebRequest(url, Headers: headers), callback); + } + public void GetUrl(string url, Dictionary headers, Delegate callback) { RequestUrl(new ScriptPluginWebRequest(url, Headers: headers), callback); } - - public void PostUrl(string url, Dictionary headers, Delegate callback) + + public void PostUrl(string url, string body, string bearerToken, Delegate callback) { - RequestUrl(new ScriptPluginWebRequest(url, null, "POST", Headers: headers), callback); + var headers = new Dictionary { { "Authorization", $"Bearer {bearerToken}" } }; + RequestUrl( + new ScriptPluginWebRequest(url, body, "POST", Headers: headers), callback); } + public void PostUrl(string url, string body, Dictionary headers, Delegate callback) + { + RequestUrl(new ScriptPluginWebRequest(url, body, "POST", Headers: headers), callback); + } + public void RequestUrl(ScriptPluginWebRequest request, Delegate callback) { Task.Run(() => @@ -77,7 +90,6 @@ public class ScriptPluginHelper { var entered = false; using var tokenSource = new CancellationTokenSource(RequestTimeout); - using var client = new HttpClient(); try diff --git a/Application/Plugin/Script/ScriptPluginV2.cs b/Application/Plugin/Script/ScriptPluginV2.cs index 63968ea3d..bfbf79904 100644 --- a/Application/Plugin/Script/ScriptPluginV2.cs +++ b/Application/Plugin/Script/ScriptPluginV2.cs @@ -278,7 +278,7 @@ public class ScriptPluginV2 : IPluginV2 typeof(ScriptPluginExtensions), typeof(LoggerExtensions)) .AllowClr(typeof(System.Net.Http.HttpClient).Assembly, typeof(EFClient).Assembly, typeof(Utilities).Assembly, typeof(Encoding).Assembly, typeof(CancellationTokenSource).Assembly, - typeof(Data.Models.Client.EFClient).Assembly, typeof(IW4MAdmin.Plugins.Stats.Plugin).Assembly) + typeof(Data.Models.Client.EFClient).Assembly, typeof(IW4MAdmin.Plugins.Stats.Plugin).Assembly, typeof(ScriptPluginWebRequest).Assembly) .CatchClrExceptions() .AddObjectConverter(new EnumsToStringConverter()));