Exemplo n.º 1
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);
            });
        }
Exemplo n.º 2
0
        public async Task HeadersReceived_Success(TestHeadersSink expectedResponseHeaders)
        {
            await RunSingleStreamTest(
                async (clientRequest, serverUri) =>
            {
                clientRequest.ConfigureRequest(contentLength: 0, hasTrailingHeaders: false);
                clientRequest.WriteRequest(HttpMethod.Get, serverUri);
                await clientRequest.CompleteRequestAsync();

                TestHeadersSink actualResponseHeaders = await clientRequest.ReadAllHeadersAsync();
                Assert.True(actualResponseHeaders.Contains(expectedResponseHeaders));
            },
                async serverStream =>
            {
                await serverStream.ReceiveAndSendAsync(headers: expectedResponseHeaders);
            });
        }