{
// Receive HEADERS frame for request.
Frame frame = await ReadFrameAsync(TimeSpan.FromSeconds(30));
+ if (frame == null)
+ {
+ throw new IOException("Failed to read Headers frame.");
+ }
Assert.Equal(FrameType.Headers, frame.Type);
Assert.Equal(FrameFlags.EndHeaders | FrameFlags.EndStream, frame.Flags);
return frame.StreamId;
// Receive HEADERS frame for request.
Frame frame = await ReadFrameAsync(Timeout).ConfigureAwait(false);
+ if (frame == null)
+ {
+ throw new IOException("Failed to read Headers frame.");
+ }
Assert.Equal(FrameType.Headers, frame.Type);
HeadersFrame headersFrame = (HeadersFrame) frame;
throw new Exception("Response body too long");
}
- await SendResponseDataAsync(streamId, responseBody, true);
+ await SendResponseDataAsync(streamId, responseBody, true).ConfigureAwait(false);
}
public override void Dispose()
public override async Task<HttpRequestData> HandleRequestAsync(HttpStatusCode statusCode = HttpStatusCode.OK, IList<HttpHeaderData> headers = null, string content = null)
{
- await EstablishConnectionAsync();
+ await EstablishConnectionAsync().ConfigureAwait(false);
- (int streamId, HttpRequestData requestData) = await ReadAndParseRequestHeaderAsync();
+ (int streamId, HttpRequestData requestData) = await ReadAndParseRequestHeaderAsync().ConfigureAwait(false);
// We are about to close the connection, after we send the response.
// So, send a GOAWAY frame now so the client won't inadvertantly try to reuse the connection.
- await SendGoAway(streamId);
+ await SendGoAway(streamId).ConfigureAwait(false);
if (content == null)
{
- await SendResponseHeadersAsync(streamId, endStream: true, statusCode, isTrailingHeader: false, headers);
+ await SendResponseHeadersAsync(streamId, endStream: true, statusCode, isTrailingHeader: false, headers).ConfigureAwait(false);
}
else
{
- await SendResponseHeadersAsync(streamId, endStream: false, statusCode, isTrailingHeader: false, headers);
- await SendResponseBodyAsync(streamId, Encoding.ASCII.GetBytes(content));
+ await SendResponseHeadersAsync(streamId, endStream: false, statusCode, isTrailingHeader: false, headers).ConfigureAwait(false);
+ await SendResponseBodyAsync(streamId, Encoding.ASCII.GetBytes(content)).ConfigureAwait(false);
}
- await WaitForConnectionShutdownAsync();
+ await WaitForConnectionShutdownAsync().ConfigureAwait(false);
return requestData;
}
{
using (var server = Http2LoopbackServer.CreateServer())
{
- await funcAsync(server, server.Address).TimeoutAfter(millisecondsTimeout);
+ await funcAsync(server, server.Address).TimeoutAfter(millisecondsTimeout).ConfigureAwait(false);
}
}
});
}
+ [Theory]
+ [InlineData("\u05D1\u05F1")]
+ [InlineData("jp\u30A5")]
+ public async Task SendAsync_InvalidHeader_Throw(string value)
+ {
+ await LoopbackServerFactory.CreateClientAndServerAsync(async uri =>
+ {
+ HttpClientHandler handler = CreateHttpClientHandler();
+ using (HttpClient client = CreateHttpClient())
+ {
+ var request = new HttpRequestMessage(HttpMethod.Get, uri);
+ Assert.True(request.Headers.TryAddWithoutValidation("bad", value));
+
+ await Assert.ThrowsAsync<HttpRequestException>(() => client.SendAsync(request));
+ }
+
+ },
+ async server =>
+ {
+ try
+ {
+ // Client should abort at some point so this is going to throw.
+ HttpRequestData requestData = await server.HandleRequestAsync(HttpStatusCode.OK).ConfigureAwait(false);
+ }
+ catch (IOException) { };
+ });
+ }
+
[Fact]
public async Task SendAsync_SpecialCharacterHeader_Success()
{