Don't block reading the StartLine.
MODIFY
WalletWasabi/Extensions/HttpRequestMessageExtensions.cs
WalletWasabi/Extensions/HttpRequestMessageExtensions.cs
@@ -32,7 +32,7 @@ namespace System.Net.Http
string startLine = await HttpMessageHelper.ReadStartLineAsync(requestStream, ctsToken);
- var requestLine = RequestLine.CreateNew(startLine);
+ var requestLine = await RequestLine.CreateNewAsync(startLine);
var request = new HttpRequestMessage(requestLine.Method, requestLine.URI);
string headers = await HttpMessageHelper.ReadHeadersAsync(requestStream, ctsToken);

MODIFY
WalletWasabi/Extensions/HttpResponseMessageExtensions.cs
WalletWasabi/Extensions/HttpResponseMessageExtensions.cs
@@ -32,7 +32,7 @@ namespace System.Net.Http
string startLine = await HttpMessageHelper.ReadStartLineAsync(responseStream);
- var statusLine = StatusLine.CreateNew(startLine);
+ var statusLine = await StatusLine.CreateNewAsync(startLine);
var response = new HttpResponseMessage(statusLine.StatusCode);
string headers = await HttpMessageHelper.ReadHeadersAsync(responseStream);

MODIFY
WalletWasabi/Http/Models/RequestLine.cs
WalletWasabi/Http/Models/RequestLine.cs
using System;
+using System.Linq;
using System.Net.Http;
+using System.Threading.Tasks;
using static WalletWasabi.Http.Constants;
namespace WalletWasabi.Http.Models
@@ -27,11 +29,11 @@ namespace WalletWasabi.Http.Models
StartLineString = Method.Method + SP + URI.AbsolutePath + URI.Query + SP + Protocol + CRLF;
}
- public static RequestLine CreateNew(string requestLineString)
+ public static async Task<RequestLine> CreateNewAsync(string requestLineString)
{
try
{
- var parts = GetParts(requestLineString);
+ var parts = (await GetPartsAsync(requestLineString)).ToArray();
var methodString = parts[0];
var uri = new Uri(parts[1]);
var protocolString = parts[2];

MODIFY
WalletWasabi/Http/Models/StartLine.cs
WalletWasabi/Http/Models/StartLine.cs
using System;
using System.Collections.Generic;
using System.IO;
+using System.Threading.Tasks;
using static WalletWasabi.Http.Constants;
namespace WalletWasabi.Http.Models
@@ -9,14 +10,13 @@ namespace WalletWasabi.Http.Models
{
public HttpProtocol Protocol { get; protected set; }
public string StartLineString { get; protected set; }
- public List<string> Parts => GetParts(StartLineString);
public override string ToString()
{
return StartLineString;
}
- public static List<string> GetParts(string startLineString)
+ public static async Task<IEnumerable<string>> GetPartsAsync(string startLineString)
{
var trimmed = "";
// check if an unexpected crlf in the startlinestring
@@ -45,7 +45,7 @@ namespace WalletWasabi.Http.Models
if (parts.Count == 2)
{
- var rest = reader.ReadToEnd();
+ var rest = await reader.ReadToEndAsync();
// startLineString must end here, the ReadToEnd returns "" if nothing to read instead of null
if (rest != "")

MODIFY
WalletWasabi/Http/Models/StatusLine.cs
WalletWasabi/Http/Models/StatusLine.cs
using System;
+using System.Linq;
using System.Net;
+using System.Threading.Tasks;
using WalletWasabi.Logging;
using static WalletWasabi.Http.Constants;
@@ -17,11 +19,11 @@ namespace WalletWasabi.Http.Models
StartLineString = Protocol + SP + (int)StatusCode + SP + StatusCode.ToReasonString() + CRLF;
}
- public static StatusLine CreateNew(string statusLineString)
+ public static async Task<StatusLine> CreateNewAsync(string statusLineString)
{
try
{
- var parts = GetParts(statusLineString);
+ var parts = (await GetPartsAsync(statusLineString)).ToArray();
var protocolString = parts[0];
var codeString = parts[1];
var reason = parts[2];

Don't block reading the StartLine.