diff options
Diffstat (limited to 'win/CS/HandBrakeWPF/Utilities')
-rw-r--r-- | win/CS/HandBrakeWPF/Utilities/HttpRequestBase.cs | 54 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/Utilities/Portable.cs | 16 |
2 files changed, 57 insertions, 13 deletions
diff --git a/win/CS/HandBrakeWPF/Utilities/HttpRequestBase.cs b/win/CS/HandBrakeWPF/Utilities/HttpRequestBase.cs index cc2898b43..fd23565e3 100644 --- a/win/CS/HandBrakeWPF/Utilities/HttpRequestBase.cs +++ b/win/CS/HandBrakeWPF/Utilities/HttpRequestBase.cs @@ -10,6 +10,7 @@ namespace HandBrakeWPF.Utilities { using System; + using System.Net; using System.Net.Http; using System.Text; using System.Threading.Tasks; @@ -20,11 +21,14 @@ namespace HandBrakeWPF.Utilities public class HttpRequestBase { - protected readonly JsonSerializerSettings jsonNetSettings = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }; - protected HttpClient client = new HttpClient(); protected string serverUrl; + protected int port; + protected string base64Token; + + private readonly JsonSerializerSettings jsonNetSettings = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }; + public async Task<ServerResponse> MakeHttpJsonPostRequest(string urlPath, string json) { if (string.IsNullOrEmpty(json)) @@ -32,14 +36,26 @@ namespace HandBrakeWPF.Utilities throw new InvalidOperationException("No Post Values Found."); } - StringContent content = new StringContent(json, Encoding.UTF8, "application/json"); - HttpResponseMessage response = await client.PostAsync(this.serverUrl + urlPath, content); - if (response != null) + using (HttpClient client = new HttpClient()) { - string returnContent = await response.Content.ReadAsStringAsync(); - ServerResponse serverResponse = new ServerResponse(response.IsSuccessStatusCode, returnContent); + HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Post, this.serverUrl + urlPath); + if (!string.IsNullOrEmpty(this.base64Token)) + { + requestMessage.Headers.Add("token", this.base64Token); + } + + requestMessage.Content = new StringContent(json, Encoding.UTF8, "application/json"); - return serverResponse; + using (HttpResponseMessage response = await client.SendAsync(requestMessage)) + { + if (response != null) + { + string returnContent = await response.Content.ReadAsStringAsync(); + ServerResponse serverResponse = new ServerResponse(response.IsSuccessStatusCode, returnContent); + + return serverResponse; + } + } } return null; @@ -47,13 +63,25 @@ namespace HandBrakeWPF.Utilities public async Task<ServerResponse> MakeHttpGetRequest(string urlPath) { - HttpResponseMessage response = await client.GetAsync(this.serverUrl + urlPath); - if (response != null) + using (HttpClient client = new HttpClient()) { - string returnContent = await response.Content.ReadAsStringAsync(); - ServerResponse serverResponse = new ServerResponse(response.IsSuccessStatusCode, returnContent); + HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Get, this.serverUrl + urlPath); + if (!string.IsNullOrEmpty(this.base64Token)) + { + requestMessage.Headers.Add("token", this.base64Token); + } + + using (HttpResponseMessage response = await client.SendAsync(requestMessage)) + { + if (response != null) + { + string returnContent = await response.Content.ReadAsStringAsync(); + ServerResponse serverResponse = null; + serverResponse = response.StatusCode == HttpStatusCode.Unauthorized ? new ServerResponse(false, returnContent) : new ServerResponse(response.IsSuccessStatusCode, returnContent); - return serverResponse; + return serverResponse; + } + } } return null; diff --git a/win/CS/HandBrakeWPF/Utilities/Portable.cs b/win/CS/HandBrakeWPF/Utilities/Portable.cs index ecde42d82..578c3fe76 100644 --- a/win/CS/HandBrakeWPF/Utilities/Portable.cs +++ b/win/CS/HandBrakeWPF/Utilities/Portable.cs @@ -193,6 +193,22 @@ namespace HandBrakeWPF.Utilities return true; // Default to On. } + public static bool IsRemoteWorkerProcessEnabled() + { + if (keyPairs.ContainsKey("remote.worker.enabled")) + { + string enabled = keyPairs["remote.worker.enabled"]; + if (!string.IsNullOrEmpty(enabled) && enabled.Trim() == "true") + { + return true; + } + + return false; + } + + return true; // Default to On. + } + /// <summary> /// The get temp directory. /// </summary> |