From 031b6b3152c4c9c52ee32173edca924f922d0f42 Mon Sep 17 00:00:00 2001 From: Marc-Andre Vezeau Date: Fri, 27 May 2022 13:44:47 -0400 Subject: [PATCH] reverted modification on de 2.0.14 --- .../Connection/HttpClientExtensions.cs | 16 ++++++++-------- src/TeamCitySharp/Connection/TeamCityCaller.cs | 8 ++++---- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/TeamCitySharp/Connection/HttpClientExtensions.cs b/src/TeamCitySharp/Connection/HttpClientExtensions.cs index 7e25d9a4..a5176bfe 100644 --- a/src/TeamCitySharp/Connection/HttpClientExtensions.cs +++ b/src/TeamCitySharp/Connection/HttpClientExtensions.cs @@ -9,12 +9,12 @@ namespace TeamCitySharp.Connection { public static class HttpClientExtensions { - public static async Task Get(this HttpClient src, string url) + public static HttpResponseMessage Get(this HttpClient src, string url) { - //TODO: quick fix, need to fix soon for a big transaction - src.Timeout=TimeSpan.FromHours(1); - var content = await src.GetAsync(url, HttpCompletionOption.ResponseHeadersRead); - return content; + //TODO: quick fix, need to fix soon for a big transaction + src.Timeout=TimeSpan.FromHours(1); + var content = src.GetAsync(url); + return content.GetAwaiter().GetResult(); } public static HttpResponseMessage Post(this HttpClient src, string url, object body, string contentType) @@ -50,9 +50,9 @@ public static HttpResponseMessage GetAsFile(this HttpClient src, string url, str { using (var response = src.Get(url)) { - response.Result.EnsureSuccessStatusCode(); + response.EnsureSuccessStatusCode(); - using (Stream contentStream = response.Result.Content.ReadAsStreamAsync().GetAwaiter().GetResult(), + using (Stream contentStream = response.Content.ReadAsStreamAsync().GetAwaiter().GetResult(), fileStream = new FileStream(tempFilename, FileMode.Create, FileAccess.Write, FileShare.None, 8192, true)) { var buffer = new byte[8192]; @@ -71,7 +71,7 @@ public static HttpResponseMessage GetAsFile(this HttpClient src, string url, str } } while (isMoreToRead); - return response.Result; + return response; } } } diff --git a/src/TeamCitySharp/Connection/TeamCityCaller.cs b/src/TeamCitySharp/Connection/TeamCityCaller.cs index d43efee8..de25c6f4 100644 --- a/src/TeamCitySharp/Connection/TeamCityCaller.cs +++ b/src/TeamCitySharp/Connection/TeamCityCaller.cs @@ -161,7 +161,7 @@ private HttpResponseMessage GetResponse(string urlPart) var url = CreateUrl(urlPart); var response = - CreateHttpClient(m_credentials.UserName, m_credentials.Password, HttpContentTypes.ApplicationJson).Get(url).Result; + CreateHttpClient(m_credentials.UserName, m_credentials.Password, HttpContentTypes.ApplicationJson).Get(url); ThrowIfHttpError(response, url); return response; } @@ -181,7 +181,7 @@ public bool Authenticate(string urlPart, bool throwExceptionOnHttpError = true) try { var httpClient = CreateHttpClient(m_credentials.UserName, m_credentials.Password, HttpContentTypes.TextPlain); - var response = httpClient.Get(CreateUrl(urlPart)).Result; + var response = httpClient.Get(CreateUrl(urlPart)); if (response.StatusCode != HttpStatusCode.OK && throwExceptionOnHttpError) { throw new AuthenticationException(); @@ -337,7 +337,7 @@ public string GetRaw(string urlPart, bool rest) var url = rest ? CreateUrl(urlPart) : CreateUrl(urlPart, false); var httpClient = CreateHttpClient(m_credentials.UserName, m_credentials.Password, HttpContentTypes.TextPlain); - var response = httpClient.Get(url).Result; + var response = httpClient.Get(url); if (IsHttpError(response)) { throw new HttpException(response.StatusCode, @@ -381,7 +381,7 @@ public bool GetBoolean(string urlPart, params object[] parts) var url = CreateUrl(urlFull); var response = - CreateHttpClient(m_credentials.UserName, m_credentials.Password, HttpContentTypes.ApplicationJson).Get(url).Result; + CreateHttpClient(m_credentials.UserName, m_credentials.Password, HttpContentTypes.ApplicationJson).Get(url); return !IsHttpError(response); } catch (Exception)