示例#1
0
        public async Task ServerWorksAfterClientDisconnect()
        {
            using (var connection = _fixture.CreateTestConnection())
            {
                var message = "Hello";
                await connection.Send(
                    "POST /ReadAndWriteSynchronously HTTP/1.1",
                    $"Content-Length: {100000}",
                    "Host: localhost",
                    "Connection: close",
                    "",
                    "");

                await connection.Send(message);

                await connection.Receive(
                    "HTTP/1.1 200 OK",
                    "");
            }

            var response = await _fixture.Client.GetAsync("HelloWorld");

            var responseText = await response.Content.ReadAsStringAsync();

            Assert.Equal("Hello World", responseText);
        }
        public async Task ReadAndWriteSlowConnection()
        {
            using (var connection = _fixture.CreateTestConnection())
            {
                var testString = "hello world";
                var request    = $"POST /ReadAndWriteSlowConnection HTTP/1.0\r\n" +
                                 $"Content-Length: {testString.Length}\r\n" +
                                 "Host: " + "localhost\r\n" +
                                 "\r\n" + testString;

                foreach (var c in request)
                {
                    await connection.Send(c.ToString());

                    await Task.Delay(10);
                }

                await connection.Receive(
                    "HTTP/1.1 200 OK",
                    "");

                await connection.ReceiveHeaders();

                for (int i = 0; i < 100; i++)
                {
                    foreach (var c in testString)
                    {
                        await connection.Receive(c.ToString());
                    }
                    await Task.Delay(10);
                }
                await connection.WaitForConnectionClose();
            }
        }