Skip to content

Instantly share code, notes, and snippets.

@antonfirsov
Created February 24, 2021 16:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save antonfirsov/7e0cd2cf3c2a8bd70892f82b72c1d55a to your computer and use it in GitHub Desktop.
Save antonfirsov/7e0cd2cf3c2a8bd70892f82b72c1d55a to your computer and use it in GitHub Desktop.
[ConditionalFact(nameof(OsSupportsWinHttpTrailingHeaders))]
public async Task Http2GetAsyncResponseHeadersReadOption_RemoteServer_TrailingHeaders_Available()
{
Uri address = new Uri("https://localhost:5001/trailers.ashx");
using (HttpClient client = CreateHttpClient())
{
Task<HttpResponseMessage> sendTask = client.GetAsync(address, HttpCompletionOption.ResponseHeadersRead);
HttpResponseMessage response = await sendTask;
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Stream stream = await response.Content.ReadAsStreamAsync(TestAsync);
byte[] data = new byte[100];
await stream.ReadAsync(data, 0, data.Length);
// Read data until EOF is reached
while (stream.Read(data, 0, data.Length) != 0) ;
var trailingHeaders = GetTrailingHeaders(response);
// "EmptyHeader" is missing with remote server, aspnet probably ignores it.
Assert.Equal(3, trailingHeaders.Count());
Assert.Contains("amazingtrailer", trailingHeaders.GetValues("MyCoolTrailerHeader"));
Assert.Contains("World", trailingHeaders.GetValues("Hello"));
// Read when already zero. Trailers shouldn't be changed.
stream.Read(data, 0, data.Length);
trailingHeaders = GetTrailingHeaders(response);
Assert.Equal(3, trailingHeaders.Count());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment