Fast-path response header connection check

This commit is contained in:
Ben Adams 2016-05-19 00:13:33 +01:00
parent 86567e1d93
commit 5eb1466487
1 changed files with 6 additions and 3 deletions

View File

@ -670,14 +670,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http
var responseHeaders = _frameHeaders.ResponseHeaders;
responseHeaders.SetReadOnly();
var hasConnection = responseHeaders.HasConnection;
var end = SocketOutput.ProducingStart();
if (_keepAlive)
if (_keepAlive && hasConnection)
{
foreach (var connectionValue in responseHeaders.HeaderConnection)
{
if (connectionValue.IndexOf("close", StringComparison.OrdinalIgnoreCase) != -1)
{
_keepAlive = false;
break;
}
}
}
@ -716,11 +719,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http
}
}
if (!_keepAlive && !responseHeaders.HasConnection && _httpVersion != HttpVersionType.Http10)
if (!_keepAlive && !hasConnection && _httpVersion != HttpVersionType.Http10)
{
responseHeaders.SetRawConnection("close", _bytesConnectionClose);
}
else if (_keepAlive && !responseHeaders.HasConnection && _httpVersion == HttpVersionType.Http10)
else if (_keepAlive && !hasConnection && _httpVersion == HttpVersionType.Http10)
{
responseHeaders.SetRawConnection("keep-alive", _bytesConnectionKeepAlive);
}