Skip to content

Commit 67b84a9

Browse files
committed
Add HPack dynamic compression
1 parent d225883 commit 67b84a9

27 files changed

+1971
-593
lines changed

src/Servers/Kestrel/Core/ref/Microsoft.AspNetCore.Server.Kestrel.Core.netcoreapp.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ public KestrelServerOptions() { }
130130
public bool AllowSynchronousIO { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
131131
public System.IServiceProvider ApplicationServices { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
132132
public Microsoft.AspNetCore.Server.Kestrel.KestrelConfigurationLoader ConfigurationLoader { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
133+
public bool DisableResponseDynamicHeaderCompression { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
133134
public bool DisableStringReuse { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
134135
public bool EnableAltSvc { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
135136
public Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerLimits Limits { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } }

src/Servers/Kestrel/Core/src/CoreStrings.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,4 +599,7 @@ For more information on configuring HTTPS see https://go.microsoft.com/fwlink/?l
599599
<data name="TransportNotFound" xml:space="preserve">
600600
<value>Unable to resolve service for type 'Microsoft.AspNetCore.Connections.IConnectionListenerFactory' while attempting to activate 'Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServer'.</value>
601601
</data>
602+
<data name="GreaterThanOrEqualToZeroRequired" xml:space="preserve">
603+
<value>A value greater than or equal to zero is required.</value>
604+
</data>
602605
</root>

src/Servers/Kestrel/Core/src/Http2Limits.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,19 @@ public int MaxStreamsPerConnection
3939
}
4040

4141
/// <summary>
42-
/// Limits the size of the header compression table, in octets, the HPACK decoder on the server can use.
42+
/// Limits the size of the header compression tables, in octets, the HPACK encoder and decoder on the server can use.
4343
/// <para>
44-
/// Value must be greater than 0, defaults to 4096
44+
/// Value must be greater than or equal to 0, defaults to 4096
4545
/// </para>
4646
/// </summary>
4747
public int HeaderTableSize
4848
{
4949
get => _headerTableSize;
5050
set
5151
{
52-
if (value <= 0)
52+
if (value < 0)
5353
{
54-
throw new ArgumentOutOfRangeException(nameof(value), value, CoreStrings.GreaterThanZeroRequired);
54+
throw new ArgumentOutOfRangeException(nameof(value), value, CoreStrings.GreaterThanOrEqualToZeroRequired);
5555
}
5656

5757
_headerTableSize = value;
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System.Diagnostics;
6+
using System.Net.Http.HPack;
7+
8+
namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.HPack
9+
{
10+
[DebuggerDisplay("Name = {Name} Value = {Value}")]
11+
internal class HPackHeaderEntry
12+
{
13+
// Header name and value
14+
public string Name;
15+
public string Value;
16+
17+
// Chained list of headers in the same bucket
18+
public HPackHeaderEntry Next;
19+
public int Hash;
20+
21+
// Compute dynamic table index
22+
public int Index;
23+
24+
// Doubly linked list
25+
public HPackHeaderEntry Before;
26+
public HPackHeaderEntry After;
27+
28+
/// <summary>
29+
/// Initialize header values. An entry will be reinitialized when reused.
30+
/// </summary>
31+
public void Initialize(int hash, string name, string value, int index, HPackHeaderEntry next)
32+
{
33+
Debug.Assert(name != null);
34+
Debug.Assert(value != null);
35+
36+
Name = name;
37+
Value = value;
38+
Index = index;
39+
Hash = hash;
40+
Next = next;
41+
}
42+
43+
public uint CalculateSize()
44+
{
45+
return (uint)HeaderField.GetLength(Name.Length, Value.Length);
46+
}
47+
48+
/// <summary>
49+
/// Remove entry from the linked list and reset header values.
50+
/// </summary>
51+
public void Remove()
52+
{
53+
Before.After = After;
54+
After.Before = Before;
55+
Before = null;
56+
After = null;
57+
Next = null;
58+
Hash = 0;
59+
Name = null;
60+
Value = null;
61+
}
62+
63+
/// <summary>
64+
/// Add before an entry in the linked list.
65+
/// </summary>
66+
public void AddBefore(HPackHeaderEntry existingEntry)
67+
{
68+
After = existingEntry;
69+
Before = existingEntry.Before;
70+
Before.After = this;
71+
After.Before = this;
72+
}
73+
}
74+
}

0 commit comments

Comments
 (0)