Skip to content
This repository was archived by the owner on Dec 18, 2018. It is now read-only.

Commit 4f773ab

Browse files
committed
Headers HasX checks to fast check
1 parent 2fa1706 commit 4f773ab

File tree

4 files changed

+17
-9
lines changed

4 files changed

+17
-9
lines changed

src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ private Task CreateResponseHeader(
640640
{
641641
var begin = SocketOutput.ProducingStart();
642642
var end = begin;
643-
if (_keepAlive)
643+
if (_keepAlive && _responseHeaders.HasConnection)
644644
{
645645
var count = _responseHeaders.HeaderConnection.Count;
646646
if (count == 1)

src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.Generated.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public partial class FrameRequestHeaders
5656
private StringValues _UserAgent;
5757

5858

59+
5960
public StringValues HeaderCacheControl
6061
{
6162
get
@@ -5109,6 +5110,10 @@ public partial class FrameResponseHeaders
51095110
private byte[] _rawContentLength;
51105111
private byte[] _rawServer;
51115112

5113+
public bool HasConnection => ((_bits & 2L) != 0);
5114+
public bool HasTransferEncoding => ((_bits & 64L) != 0);
5115+
public bool HasContentLength => ((_bits & 2048L) != 0);
5116+
51125117
public StringValues HeaderCacheControl
51135118
{
51145119
get

src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseHeaders.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,6 @@ public partial class FrameResponseHeaders : FrameHeaders
1313
private static byte[] _CrLf = new[] { (byte)'\r', (byte)'\n' };
1414
private static byte[] _colonSpace = new[] { (byte)':', (byte)' ' };
1515

16-
public bool HasConnection => HeaderConnection.Count != 0;
17-
18-
public bool HasTransferEncoding => HeaderTransferEncoding.Count != 0;
19-
20-
public bool HasContentLength => HeaderContentLength.Count != 0;
21-
22-
2316
public Enumerator GetEnumerator()
2417
{
2518
return new Enumerator(this);

tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class KnownHeader
2525
public int BytesOffset { get; set; }
2626
public int BytesCount { get; set; }
2727
public bool EnhancedSetter { get; set; }
28+
public bool FastCheck { get; set; }
2829
public string TestBit() => $"((_bits & {1L << Index}L) != 0)";
2930
public string SetBit() => $"_bits |= {1L << Index}L";
3031
public string ClearBit() => $"_bits &= ~{1L << Index}L";
@@ -139,6 +140,12 @@ public static string GeneratedFile()
139140
"Transfer-Encoding",
140141
"Content-Length",
141142
};
143+
var fastCheckHeaders = new[]
144+
{
145+
"Connection",
146+
"Transfer-Encoding",
147+
"Content-Length",
148+
};
142149
var responseHeaders = commonHeaders.Concat(new[]
143150
{
144151
"Accept-Ranges",
@@ -155,7 +162,8 @@ public static string GeneratedFile()
155162
{
156163
Name = header,
157164
Index = index,
158-
EnhancedSetter = enhancedHeaders.Contains(header)
165+
EnhancedSetter = enhancedHeaders.Contains(header),
166+
FastCheck = fastCheckHeaders.Contains(header)
159167
}).ToArray();
160168
var loops = new[]
161169
{
@@ -208,6 +216,8 @@ public partial class {loop.ClassName}
208216
private StringValues _" + header.Identifier + ";")}
209217
{Each(loop.Headers.Where(header => header.EnhancedSetter), header => @"
210218
private byte[] _raw" + header.Identifier + ";")}
219+
{Each(loop.Headers.Where(header => header.FastCheck), header => @"
220+
public bool Has" + header.Identifier + $" => {header.TestBit()};")}
211221
{Each(loop.Headers, header => $@"
212222
public StringValues Header{header.Identifier}
213223
{{

0 commit comments

Comments
 (0)