Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply async best practices to Tor library #2137

Merged
merged 6 commits into from Aug 21, 2019
Next

Don't block the thread reading the header field.

  • Loading branch information...
nopara73 committed Aug 20, 2019
commit 0fac56e07299151b77574450fe8a21b49927d18f
@@ -37,7 +37,7 @@ public static async Task<HttpRequestMessage> CreateNewAsync(Stream requestStream

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);
@@ -37,7 +37,7 @@ public static async Task<HttpResponseMessage> CreateNewAsync(Stream responseStre

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);
@@ -359,7 +359,7 @@ private static async Task<byte[]> GetDecodedChunkedContentBytesAsync(Stream stre
// 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)
{
@@ -1,5 +1,6 @@
using System;
using System.IO;
using System.Threading.Tasks;
using WalletWasabi.Helpers;
using static WalletWasabi.Http.Constants;

@@ -49,7 +50,7 @@ public override string ToString()
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 @@ public static HeaderField CreateNew(string fieldString)
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);
@@ -5,6 +5,7 @@
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 @@ public override string ToString()
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 @@ public static HeaderSection CreateNew(string headersString)
{
break;
}
hs.Fields.Add(HeaderField.CreateNew(field));
hs.Fields.Add(await HeaderField.CreateNewAsync(field));
This conversation was marked as resolved by nopara73

This comment has been minimized.

Copy link
@lontivero

lontivero Aug 20, 2019

Collaborator

It would be good to have this in two different lines.

This comment has been minimized.

Copy link
@nopara73

nopara73 Aug 21, 2019

Author Collaborator

I removed the streamreaders, hence the source of the asynchronoucity in status lines.

}

ValidateAndCorrectHeaders(hs);
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.