Skip to content

Commit

Permalink
Merge pull request #18 from Strafe153/strafe153/configure_await
Browse files Browse the repository at this point in the history
Added ConfigureAwait(false)
  • Loading branch information
JTOne123 authored Apr 9, 2024
2 parents c89fef7 + 5b2d1f1 commit da11f03
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
5 changes: 4 additions & 1 deletion LiqPaySDK/LiqPay.SDK/LiqPayClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ private void CheckRequired()
public async Task<LiqPayResponse> RequestAsync(string path, LiqPayRequest requestParams)
{
var data = PrepareRequestData(requestParams);
string response = await LiqPayClientHelper.PostAsync(LiqPayConsts.LiqpayApiUrl + path, data, Proxy);

string response = await LiqPayClientHelper
.PostAsync($"{LiqPayConsts.LiqpayApiUrl}{path}", data, Proxy)
.ConfigureAwait(false);

return JsonConvert.DeserializeObject<LiqPayResponse>(response);
}
Expand Down
16 changes: 10 additions & 6 deletions LiqPaySDK/LiqPay.SDK/LiqPayClientHelper.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;
Expand All @@ -12,7 +11,6 @@ public class LiqPayClientHelper
{
public static async Task<string> PostAsync(string url, Dictionary<string, string> data, WebProxy proxy = null)
{
string urlParameters = null;
var parameters = new List<string>();
foreach (var item in data)
{
Expand All @@ -22,7 +20,7 @@ public static async Task<string> PostAsync(string url, Dictionary<string, string

parameters.Add($"{item.Key}={utf8QueryValue}");
}
urlParameters = string.Join("&", parameters);

var httpClientHandler = new HttpClientHandler()
{
Proxy = proxy
Expand All @@ -31,13 +29,19 @@ public static async Task<string> PostAsync(string url, Dictionary<string, string
using (var httpClient = new HttpClient(httpClientHandler))
{
var encoding = Encoding.GetEncoding(Encoding.UTF8.CodePage);
using (var responseMessage = await httpClient.PostAsync(url, new StringContent(urlParameters)))

var urlParameters = string.Join("&", parameters);
var stringContent = new StringContent(urlParameters);

using (var responseMessage = await httpClient.PostAsync(url, stringContent).ConfigureAwait(false))
{
responseMessage.EnsureSuccessStatusCode();

using (var responseStream = await responseMessage.Content.ReadAsStreamAsync())
using (var responseStream = await responseMessage.Content.ReadAsStreamAsync().ConfigureAwait(false))
using (var reader = new StreamReader(responseStream, encoding))
return reader.ReadToEnd();
{
return reader.ReadToEnd();
}
}
}
}
Expand Down

0 comments on commit da11f03

Please sign in to comment.