Пример #1
0
        public async Task Send_ChunkedRequest_Success(int testIdx, TestHeadersSink requestHeaders, List <string> requestContent, TestHeadersSink requestTrailingHeaders)
        {
            _ = testIdx; // only used to assist debugging.

            await RunSingleStreamTest(
                async (client, serverUri) =>
            {
                long contentLength = requestContent.Sum(x => (long)x.Length);
                client.ConfigureRequest(contentLength, hasTrailingHeaders: true);
                client.WriteRequest(HttpMethod.Post, serverUri);
                client.WriteHeaders(requestHeaders);

                foreach (string content in requestContent)
                {
                    await client.WriteContentAsync(content);
                }

                client.WriteTrailingHeaders(requestTrailingHeaders);

                await client.CompleteRequestAsync();
            },
                async server =>
            {
                HttpTestFullRequest request = await server.ReceiveAndSendAsync();

                if (request.Version.Major == 1)
                {
                    Assert.Equal("chunked", request.Headers.GetSingleValue("transfer-encoding"));
                }

                Assert.True(request.Headers.Contains(requestHeaders));
                Assert.Equal(string.Join("", requestContent), request.Content);
                Assert.True(request.TrailingHeaders.Contains(requestTrailingHeaders));
            });
        }
Пример #2
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.ReadToResponseAsync());
                Version version = client.Version !;

                TestHeadersSink headers = await client.ReadAllHeadersAsync();

                if (version.Major == 1)
                {
                    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);
            });
        }