public async Task Pipelining_Success()
        {
            const int PipelineLength = 10;

            await RunMultiStreamTest(
                async (client, serverUri) =>
            {
                var tasks = new Task[PipelineLength];

                for (int i = 0; i < tasks.Length; ++i)
                {
                    tasks[i] = MakeRequest(i);
                }

                await tasks.WhenAllOrAnyFailed(10_000);

                async Task MakeRequest(int requestNo)
                {
                    await using ValueHttpRequest request = (await client.CreateNewRequestAsync(Version, HttpVersionPolicy.RequestVersionExact)).Value;

                    request.ConfigureRequest(contentLength: 0, hasTrailingHeaders: false);
                    request.WriteRequest(HttpMethod.Get, serverUri);
                    request.WriteHeader("X-Request-No", requestNo.ToString(CultureInfo.InvariantCulture));
                    await request.CompleteRequestAsync();

                    TestHeadersSink headers = await request.ReadAllHeadersAsync();

                    Assert.Equal(requestNo.ToString(CultureInfo.InvariantCulture), headers.GetSingleValue("X-Response-No"));
                }
            },
                async server =>
            {
                var streams = new (HttpTestStream, HttpTestFullRequest)[PipelineLength];

                for (int i = 0; i < streams.Length; ++i)
                {
                    HttpTestStream stream       = await server.AcceptStreamAsync();
                    HttpTestFullRequest request = await stream.ReceiveFullRequestAsync();
                    Assert.Equal(i.ToString(CultureInfo.InvariantCulture), request.Headers.GetSingleValue("X-Request-No"));
                    streams[i] = (stream, request);
                }

                for (int i = 0; i < streams.Length; ++i)
                {
                    (HttpTestStream stream, HttpTestFullRequest request) = streams[i];

                    var responseHeaders = new TestHeadersSink()
                    {
                        { "X-Response-No", i.ToString(CultureInfo.InvariantCulture) }
                    };

                    await stream.SendResponseAsync(headers: responseHeaders);
                    await stream.DisposeAsync();
                }
            });
Beispiel #2
0
        public async Task Receive_LWS_Success()
        {
            await RunSingleStreamTest(
                async (clientRequest, serverUri) =>
            {
                clientRequest.ConfigureRequest(contentLength: 0, hasTrailingHeaders: false);
                clientRequest.WriteRequest(HttpMethod.Get, serverUri);
                await clientRequest.CompleteRequestAsync();

                TestHeadersSink responseHeaders = await clientRequest.ReadAllHeadersAsync();
                Assert.Equal("foo   bar   baz", responseHeaders.GetSingleValue("X-Test-Header"));
            },
                async serverStream =>
            {
                HttpTestFullRequest request = await serverStream.ReceiveFullRequestAsync();
                await((Http1TestStream)serverStream).SendRawResponseAsync("HTTP/1.1 200 OK\r\nX-Test-Header: foo\r\n\tbar\r\n baz\r\n\r\n");
            });
        }
Beispiel #3
0
        public async Task Receive_ChunkedResponse_Success(int testIdx, TestHeadersSink responseHeaders, List <string> responseContent, TestHeadersSink responseTrailingHeaders)
        {
            _ = testIdx; // only used to assist debugging.

            await RunSingleStreamTest(
                async (client, serverUri) =>
            {
                client.ConfigureRequest(contentLength: 0, hasTrailingHeaders: false);
                client.WriteRequest(HttpMethod.Get, serverUri);
                client.WriteHeader("TE", "trailers");
                await client.CompleteRequestAsync();

                Assert.True(await client.ReadToFinalResponseAsync());

                Version version = client.Version !;
                Assert.NotNull(version);

                TestHeadersSink headers = await client.ReadAllHeadersAsync();

                if (version.Major == Version.Major)
                {
                    Assert.Equal("chunked", headers.GetSingleValue("transfer-encoding"));
                }

                Assert.True(headers.Contains(responseHeaders));

                string content = await client.ReadAllContentAsStringAsync();
                Assert.Equal(string.Join("", responseContent), content);

                TestHeadersSink trailers = await client.ReadAllTrailingHeadersAsync();
                Assert.True(trailers.Contains(responseTrailingHeaders));
            },
                async server =>
            {
                await server.ReceiveAndSendChunkedAsync(headers: responseHeaders, content: responseContent, trailingHeaders: responseTrailingHeaders);
            });
        }