-
Notifications
You must be signed in to change notification settings - Fork 10.3k
HTTP/3: Write static header names #38565
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
83 changes: 83 additions & 0 deletions
83
src/Servers/Kestrel/Core/test/Http3/Http3QPackEncoderTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; | ||
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http3; | ||
|
||
namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests; | ||
|
||
public class Http3QPackEncoderTests | ||
{ | ||
[Fact] | ||
public void BeginEncodeHeaders_StatusWithoutIndexedValue_WriteIndexNameAndFullValue() | ||
{ | ||
Span<byte> buffer = new byte[1024 * 16]; | ||
|
||
var totalHeaderSize = 0; | ||
var headers = new HttpResponseHeaders(); | ||
var enumerator = new Http3HeadersEnumerator(); | ||
enumerator.Initialize(headers); | ||
|
||
Assert.True(QPackHeaderWriter.BeginEncodeHeaders(302, enumerator, buffer, ref totalHeaderSize, out var length)); | ||
|
||
var result = buffer.Slice(0, length).ToArray(); | ||
var hex = BitConverter.ToString(result); | ||
Assert.Equal("00-00-5F-30-03-33-30-32", hex); | ||
} | ||
|
||
[Fact] | ||
public void BeginEncodeHeaders_StatusWithIndexedValue_WriteIndex() | ||
{ | ||
Span<byte> buffer = new byte[1024 * 16]; | ||
|
||
var totalHeaderSize = 0; | ||
var headers = new HttpResponseHeaders(); | ||
var enumerator = new Http3HeadersEnumerator(); | ||
enumerator.Initialize(headers); | ||
|
||
Assert.True(QPackHeaderWriter.BeginEncodeHeaders(200, enumerator, buffer, ref totalHeaderSize, out var length)); | ||
|
||
var result = buffer.Slice(0, length).ToArray(); | ||
var hex = BitConverter.ToString(result); | ||
Assert.Equal("00-00-D9", hex); | ||
} | ||
|
||
[Fact] | ||
public void BeginEncodeHeaders_NonStaticKey_WriteFullNameAndFullValue() | ||
{ | ||
Span<byte> buffer = new byte[1024 * 16]; | ||
|
||
var headers = (IHeaderDictionary)new HttpResponseHeaders(); | ||
headers.Translate = "private"; | ||
|
||
var totalHeaderSize = 0; | ||
var enumerator = new Http3HeadersEnumerator(); | ||
enumerator.Initialize(headers); | ||
|
||
Assert.True(QPackHeaderWriter.BeginEncodeHeaders(302, enumerator, buffer, ref totalHeaderSize, out var length)); | ||
|
||
var result = buffer.Slice(8, length - 8).ToArray(); | ||
var hex = BitConverter.ToString(result); | ||
Assert.Equal("37-02-74-72-61-6E-73-6C-61-74-65-07-70-72-69-76-61-74-65", hex); | ||
} | ||
|
||
[Fact] | ||
public void BeginEncodeHeaders_NoStatus_NonStaticKey_WriteFullNameAndFullValue() | ||
{ | ||
Span<byte> buffer = new byte[1024 * 16]; | ||
|
||
var headers = (IHeaderDictionary)new HttpResponseHeaders(); | ||
headers.Translate = "private"; | ||
|
||
var totalHeaderSize = 0; | ||
var enumerator = new Http3HeadersEnumerator(); | ||
enumerator.Initialize(headers); | ||
|
||
Assert.True(QPackHeaderWriter.BeginEncodeHeaders(enumerator, buffer, ref totalHeaderSize, out var length)); | ||
|
||
var result = buffer.Slice(2, length - 2).ToArray(); | ||
var hex = BitConverter.ToString(result); | ||
Assert.Equal("37-02-74-72-61-6E-73-6C-61-74-65-07-70-72-69-76-61-74-65", hex); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should consider adding the un-"known" response headers given the methodology described in the quickwg QPACK static table appendix.
I also think the following headers only make sense on the request: Cookie, Authorization, UserAgent, Referer, Origin, IfModifiedSince, IfNoneMatch, Method, Accept, AcceptEncoding, AcceptLanguage, Range, IfRange and UpgradeInsecureRequests
Do we think there would be much value in trying to use the static header values too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't add more known headers because there is a limit to how many we can have. Eventually, the bit flags will be too large for 64bits.
I will look at using the static table for values in a future PR. It will require greater changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, remove request headers from this list, if only to make it easier to reason about.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For HPACK, we have the complete list:
aspnetcore/src/Servers/Kestrel/Core/src/Internal/Http2/Http2HeadersEnumerator.cs
Lines 149 to 203 in 465f929
Do you want to trim the HPACK list as well? Which items?
Or leave both HPACK and QPACK lists as is?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, ok, leave it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks to me that Http2HeadersEnumerator.GetResponseHeaderStaticTableId() only handles response headers. I don't see request headers like Cookie, Authorization or any of the rest in there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right. I'll make the change to remove them in another PR.