Skip to content

Commit 448450d

Browse files
committed
PR feedback
1 parent 2bddabf commit 448450d

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/Servers/Kestrel/Core/src/Internal/Http2/HPack/Http2HPackEncoder.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ public Http2HPackEncoder(uint maxHeaderTableSize = Http2PeerSettings.DefaultHead
3434
_maxHeaderListSize = Http2PeerSettings.DefaultMaxHeaderListSize;
3535
Head = new HPackHeaderEntry();
3636
Head.Initialize(-1, string.Empty, string.Empty, int.MaxValue, null);
37+
// Bucket count balances memory usage and the expected low number of headers (constrained by the header table size).
38+
// Performance with different bucket counts hasn't been measured in detail.
3739
_headerBuckets = new HPackHeaderEntry[16];
3840
_hashMask = (byte)(_headerBuckets.Length - 1);
3941
Head.Before = Head.After = Head;
@@ -52,7 +54,7 @@ public void UpdateMaxHeaderTableSize(uint maxHeaderTableSize)
5254
}
5355
}
5456

55-
public void SetMaxHeaderListSize(uint maxHeaderListSize)
57+
public void UpdateMaxHeaderListSize(uint maxHeaderListSize)
5658
{
5759
_maxHeaderListSize = maxHeaderListSize;
5860
}

src/Servers/Kestrel/Core/src/Internal/Http2/Http2Connection.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -717,9 +717,6 @@ private Task ProcessSettingsFrameAsync(in ReadOnlySequence<byte> payload)
717717

718718
_clientSettings.Update(Http2FrameReader.ReadSettings(payload));
719719

720-
// Maximum encoder size is limited by the configured max on the server
721-
_frameWriter.UpdateMaxHeaderTableSize(Math.Min(_clientSettings.HeaderTableSize, (uint)Limits.Http2.HeaderTableSize));
722-
723720
// Ack before we update the windows, they could send data immediately.
724721
var ackTask = _frameWriter.WriteSettingsAckAsync();
725722

@@ -746,6 +743,15 @@ private Task ProcessSettingsFrameAsync(in ReadOnlySequence<byte> payload)
746743
}
747744
}
748745

746+
// Maximum HPack encoder size is limited by Http2Limits.HeaderTableSize, configured max the server.
747+
//
748+
// Note that the client HPack decoder doesn't care about the ACK so we don't need to lock sending the
749+
// ACK and updating the table size on the server together.
750+
// The client will wait until a size agreed upon by it (sent in SETTINGS_HEADER_TABLE_SIZE) and the
751+
// server (sent as a dynamic table size update in the next HEADERS frame) is received before applying
752+
// the new size.
753+
_frameWriter.UpdateMaxHeaderTableSize(Math.Min(_clientSettings.HeaderTableSize, (uint)Limits.Http2.HeaderTableSize));
754+
749755
return ackTask.AsTask();
750756
}
751757
catch (Http2SettingsParameterOutOfRangeException ex)

0 commit comments

Comments
 (0)