Don't block the thread reading the header field.
MODIFY
WalletWasabi/Extensions/HttpRequestMessageExtensions.cs
WalletWasabi/Extensions/HttpRequestMessageExtensions.cs
@@ -37,7 +37,7 @@ namespace System.Net.Http
string headers = await HttpMessageHelper.ReadHeadersAsync(requestStream, ctsToken);
- var headerSection = HeaderSection.CreateNew(headers);
+ var headerSection = await HeaderSection.CreateNewAsync(headers);
var headerStruct = headerSection.ToHttpRequestHeaders();
HttpMessageHelper.AssertValidHeaders(headerStruct.RequestHeaders, headerStruct.ContentHeaders);

MODIFY
WalletWasabi/Extensions/HttpResponseMessageExtensions.cs
WalletWasabi/Extensions/HttpResponseMessageExtensions.cs
@@ -37,7 +37,7 @@ namespace System.Net.Http
string headers = await HttpMessageHelper.ReadHeadersAsync(responseStream);
- var headerSection = HeaderSection.CreateNew(headers);
+ var headerSection = await HeaderSection.CreateNewAsync(headers);
var headerStruct = headerSection.ToHttpResponseHeaders();
HttpMessageHelper.AssertValidHeaders(headerStruct.ResponseHeaders, headerStruct.ContentHeaders);

MODIFY
WalletWasabi/Helpers/HttpMessageHelper.cs
WalletWasabi/Helpers/HttpMessageHelper.cs
@@ -359,7 +359,7 @@ namespace System.Net.Http
// of a chunked message in order to supply metadata that might be
// dynamically generated while the message body is sent
string trailerHeaders = await ReadHeadersAsync(stream, ctsToken);
- var trailerHeaderSection = HeaderSection.CreateNew(trailerHeaders);
+ var trailerHeaderSection = await HeaderSection.CreateNewAsync(trailerHeaders);
RemoveInvalidTrailers(trailerHeaderSection);
if (responseHeaders != null)
{

MODIFY
WalletWasabi/Http/Models/HeaderField.cs
WalletWasabi/Http/Models/HeaderField.cs
using System;
using System.IO;
+using System.Threading.Tasks;
using WalletWasabi.Helpers;
using static WalletWasabi.Http.Constants;
@@ -49,7 +50,7 @@ namespace WalletWasabi.Http.Models
return ToString(true);
}
- public static HeaderField CreateNew(string fieldString)
+ public static async Task<HeaderField> CreateNewAsync(string fieldString)
{
fieldString = fieldString.TrimEnd(CRLF, StringComparison.Ordinal);
@@ -71,7 +72,7 @@ namespace WalletWasabi.Http.Models
throw new FormatException($"Wrong {nameof(HeaderField)}: {fieldString}.");
}
- var value = reader.ReadToEnd();
+ var value = await reader.ReadToEndAsync();
value = Guard.Correct(value);
return new HeaderField(name, value);

MODIFY
WalletWasabi/Http/Models/HeaderSection.cs
WalletWasabi/Http/Models/HeaderSection.cs
@@ -5,6 +5,7 @@ using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
+using System.Threading.Tasks;
using static WalletWasabi.Http.Constants;
namespace WalletWasabi.Http.Models
@@ -32,7 +33,7 @@ namespace WalletWasabi.Http.Models
return ToString(false);
}
- public static HeaderSection CreateNew(string headersString)
+ public static async Task<HeaderSection> CreateNewAsync(string headersString)
{
headersString = HeaderField.CorrectObsFolding(headersString);
@@ -51,7 +52,7 @@ namespace WalletWasabi.Http.Models
{
break;
}
- hs.Fields.Add(HeaderField.CreateNew(field));
+ hs.Fields.Add(await HeaderField.CreateNewAsync(field));
}
ValidateAndCorrectHeaders(hs);

Don't block the thread reading the header field.