Add functional regression test for 'Connection: keep-alive, upgrade' request header.

This commit is contained in:
Cesar Blum Silveira 2016-11-04 16:14:06 -07:00
parent ed98894c93
commit 5b65117b64
1 changed files with 42 additions and 0 deletions

View File

@ -14,6 +14,7 @@ using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Features;
using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking;
using Microsoft.AspNetCore.Testing.xunit;
using Microsoft.Extensions.Logging.Testing;
@ -190,6 +191,47 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
}
}
[Fact]
public void CanUpgradeRequestWithConnectionKeepAliveUpgradeHeader()
{
var dataRead = false;
var builder = new WebHostBuilder()
.UseKestrel()
.UseUrls($"http://127.0.0.1:0")
.Configure(app =>
{
app.Run(async context =>
{
var stream = await context.Features.Get<IHttpUpgradeFeature>().UpgradeAsync();
var data = new byte[3];
var bytesRead = 0;
while (bytesRead < 3)
{
bytesRead += await stream.ReadAsync(data, bytesRead, data.Length - bytesRead);
}
dataRead = Encoding.ASCII.GetString(data, 0, 3) == "abc";
});
});
using (var host = builder.Build())
{
host.Start();
using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
{
socket.Connect(new IPEndPoint(IPAddress.Loopback, host.GetPort()));
socket.Send(Encoding.ASCII.GetBytes("GET / HTTP/1.1\r\nConnection: keep-alive, upgrade\r\n\r\n"));
socket.Send(Encoding.ASCII.GetBytes("abc"));
while (socket.Receive(new byte[1024]) > 0) ;
}
}
Assert.True(dataRead);
}
[Fact]
public async Task ConnectionResetAbortsRequest()
{