Created
February 24, 2021 16:07
-
-
Save antonfirsov/7e0cd2cf3c2a8bd70892f82b72c1d55a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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