Repository navigation
feat!: 4.0 Client Hints API: data-minimizing defaults, brand lists, Critical-CH and Vary, package validation - #25
Open
BenjaminAbt wants to merge 23 commits into
Open
BenjaminAbt wants to merge 23 commits into
BenjaminAbt wants to merge 23 commits into
Conversation
- Set ContinuousIntegrationBuild in GitHub Actions. The embedded PDBs of the
published packages contained paths of the build agent
(/home/runner/work/...); they are now mapped to /_/.
- Fix the product name of the core package ("HTTP Client Agents") and the
descriptions of both packages. Client Hints do not identify bots.
- Use single-word tags: NuGet split "User Agent" into "User" and "Agent".
- Add Copyright and PackageReleaseNotes.
- Run dotnet format --verify-no-changes in every build. - Pin dotnet/nbgv to v0.5.2 instead of the master branch. - Update actions/download-artifact from v4 to v8, which runs on Node.js 24. The packages are downloaded by name, which v5 to v8 did not change. - Add Dependabot for NuGet and GitHub Actions with grouped updates. Microsoft.Extensions.Primitives stays at the lowest version for .NET 8.
- SECURITY.md asked to report vulnerabilities in public issues. It now points to GitHub private vulnerability reporting. - Replace the unrelated Azure rule in copilot-instructions.md with the build, test, code and documentation rules of this repository. - Replace the solution item for the missing ci.yml with the existing workflow files and dependabot.yml.
The report that dotnet test merges keeps the hits of only one test project for a package. The core package is covered by its own tests and partly by the ASP.NET Core tests, so the gate measured the coverage of the ASP.NET Core tests only. The script now reads the report of every test project and target framework and takes, for every line, the highest coverage of any report. Cobertura does not record which branches are covered, so the branch coverage is a lower bound. Lines that are not covered are listed.
…64 and FormFactors - HttpClientHintsInterpreter.DecodeBrandList parses Sec-CH-UA and Sec-CH-UA-Full-Version-List into HttpClientHintsBrand (Brand, Version, IsGrease). Parameters other than v are ignored. - DecodeStructuredStringList decodes Sec-CH-UA-Form-Factors, and DecodeStructuredBoolean decodes Sec-CH-UA-Mobile and Sec-CH-UA-WoW64. IsMobile uses it and now ignores surrounding whitespace. - HttpClientHints and HttpClientHintsView: DecodedUA, DecodedFullVersionList, Bitness, DecodedBitness, Wow64, FormFactors and DecodedFormFactors. The record gets the new values as init properties, so its constructor does not change. - An internal StructuredFieldReader implements the RFC 9651 parsing; DecodeStructuredString uses it without changing its results.
… Vary BREAKING CHANGES - Platform, Architecture and Device are false by default. Only Sec-CH-UA and Sec-CH-UA-Mobile, which browsers send with every request, are requested without configuration. - Accept-CH no longer contains User-Agent, which is not a Client Hint. - HttpClientHintsMiddlewareConfig and HttpClientHintsRequestMiddleware are internal. Use AddHttpClientHints and UseHttpClientHints. Features - FullVersionList requests Sec-CH-UA-Full-Version-List. Architecture also requests Sec-CH-UA-WoW64, Device also Sec-CH-UA-Form-Factors. - Critical sets Critical-CH and adds the hints to Accept-CH and Vary. Vary adds all requested hints to the Vary header. - Empty entries and duplicates in Additional and Critical are ignored. - Lifetime is obsolete: browsers ignore Accept-CH-Lifetime, which was removed from the Client Hints specification. It still sets the header. The middleware stays async. The smoke test, benchmarks and sample use the new options. The public key is on one line for InternalsVisibleTo.
- Package validation compares the API with the packages 3.3.5 on NuGet.org. CompatibilitySuppressions.xml lists the two types that are now internal. - CI packs in every build, so pull requests are validated as well. - The packages contain a 128x128 icon (29 KB) instead of the 512x512 logo (281 KB). The logo for the readme is compressed losslessly (244 KB).
- Options with requested hints, entropy and defaults; Critical, Vary and the obsolete Lifetime; resulting response headers. - Decoded values for every header, the decoders of HttpClientHintsInterpreter and their rules, brand lists and GREASE brands. - Coverage gate, package validation and the baseline update after a release. - Benchmarks measured again with the new snapshot values, brand list decoding and the Critical-CH and Vary middleware.
The packages use res/httpclienthints-icon.png; no file references the old logo.
The autolabeler rules in release-drafter.yml never ran: Release Drafter runs
only on pushes to main, and the autolabeler needs pull request events. The
rules also expected feature/ branches and "feature" in the title, while this
repository uses Conventional Commits.
- pr-labeler.yml runs Release Drafter on pull_request_target with
disable-releaser, so pull requests from forks are labeled as well. It does
not check out code of the pull request.
- Every pull request gets one category label from the type in its title.
Release Drafter v6 lists a pull request in every category whose labels it
has, so a breaking change ("feat!:") gets only breaking-change, and the
dependencies rule for project files is removed; Dependabot sets that label.
- New category "Breaking Changes", listed first.
The reader created the StringBuilder of an escaped string with the length of the whole header. A list with many escaped members allocated O(n²): decoding a 16 KB brand list twice allocated 180 MB. The builder now starts with the default capacity: 8, 16 and 32 KB headers allocate 241 KB, 481 KB and 961 KB. Found in review.
Older Chromium versions put the special characters before "Not" and also use quote and backslash, for example ";Not A Brand" or "\"Not\A;Brand". IsGrease now accepts the letters NotABrand in this order with any of the characters ()-./:;=?_"\ around them. Found in review.
- Additional and Critical: entries are trimmed. An entry that is not a valid header name (a space, a comma, quotes, a leading digit) makes AddHttpClientHints throw an ArgumentException, because browsers ignore the whole Accept-CH header if one member is not a token. - The middleware adds its Vary values once per response, also when the pipeline runs again, for example with UseStatusCodePagesWithReExecute. - UA, FullVersionList and FormFactors combine a header sent in several field lines, as RFC 9651 requires for lists. Other headers keep using the first line. - The obsolete Lifetime sends whole seconds independent of the current culture; de-DE sent "1,5". Found in review.
- Lines are keyed per class: a covered method no longer hides an uncovered lambda on the same source line. - Branches with a different number of branches per target framework are counted per number, so the branch coverage stays a lower bound. - A report without packages or classes no longer stops the script. Found in review.
- Options: trimming and validation of names, Vary once per response. - Decoded values: list headers in several field lines; GREASE rule with the forms of older Chromium versions. - Coverage gate: lines per class, empty results directory. - Benchmarks measured again.
main accepts changes only through pull requests whose Build and Test and Native AOT checks have passed.
- The list decoders return arrays of the exact size instead of a List: a list has at most one member more than commas, so the number of commas gives a safe upper bound. An empty header returns an empty array without allocating. - Keys, tokens and the white space between members are a few characters long. Scalar loops skip them faster than vectorized searches, whose setup dominated for these lengths. A vectorized search for the end of a string was measured as well and was slower, so strings keep the scalar loop. ReadDecodedBrandLists (two lists with three brands): 266 ns, 744 B -> 158 ns, 648 B.
The Decoded* properties of HttpClientHints decode on the first access and return the same result afterwards. GetClientHints(HttpContext) and the feature return one record per request, so every value of a request is decoded at most once: reading both brand lists again takes 10 ns and allocates nothing, instead of 158 ns and 648 B. The values are held in a field whose equality is always true, so record equality and GetHashCode do not change. A record created with a with expression detects that the values belong to the original and decodes its own. The field adds 16 B to the record (104 B -> 120 B); the values object is allocated only on the first access of a Decoded* property.
The record decodes each value once, the view on every access. Benchmarks measured again, with ReadDecodedBrandListsFromCachedSnapshot.
feat(tests): add tests for Vary header restoration fix(interpreter): validate long UTF-8 display strings fix(tests): ensure headers are released before decoding chore(deps): update Nerdbank.GitVersioning to 3.10.94
feat(tests): add unit tests for release draft updates feat(middleware): enhance Vary header handling for caching feat(docs): improve documentation for ASP.NET Core caching fix(samples): update sample project for new configurations refactor(python): implement release package download script chore(release): add changelog configuration for releases chore(release): create release notes for version 4.0
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
This PR also brings #24 into
main. #24 was merged into the branch of #23 after #23 had already been merged, so its changes are not inmain. The first three commits (114bdd8, 7e1bc8b, a333e16) are the reviewed commits of #24, unchanged; their tree is identical to the merge commit 92e9b45 of #24. The new changes start with fd9df97.This PR contains the API changes for 4.0: privacy-friendly defaults, decoding of all User-Agent Client Hints including the brand lists,
Critical-CHandVary, package validation against 3.3.5, a smaller package icon, and labels for the release notes. It also fixes the coverage gate, which measured the core package with the ASP.NET Core tests only. An independent review of the parser and the options found five problems, which are fixed in this PR (see Review fixes).Breaking changes
Platform,ArchitectureandDevicearefalseby default. Without configuration,Accept-CHrequests onlySec-CH-UAandSec-CH-UA-Mobile.true.Accept-CHno longer containsUser-Agent. It is not a Client Hint; browsers send it anyway.HttpClientHintsMiddlewareConfigandHttpClientHintsRequestMiddlewareareinternal.AddHttpClientHintsandUseHttpClientHints.AdditionalorCriticalthat is not a valid header name (a space, a comma, quotes, a leading digit) makesAddHttpClientHintsthrow anArgumentException. Before, it was sent as is, and browsers ignored the wholeAccept-CHheader. Entries are trimmed.UA,FullVersionListandFormFactorscombine a header sent in several field lines, as RFC 9651 requires for lists. Before, they returned the first line.HttpClientHintsOptions.Lifetimeis[Obsolete]:Accept-CH-Lifetimewas removed from the Client Hints specification, and browsers ignore it. It still sets the header, now in whole seconds independent of the culture.IsMobileignores leading and trailing whitespace (" ?1 "→true, wasnull).Package validation reports only the two internalized types; they are listed in
src/HttpClientHints.AspNetCore/CompatibilitySuppressions.xml. The constructor of theHttpClientHintsrecord does not change: the new values areinitproperties.Features
HttpClientHintsInterpreter.DecodeBrandListand the propertiesDecodedUA/DecodedFullVersionListreturnHttpClientHintsBrand(Brand,Version,IsGrease).IsGreaserecognizes the GREASE brands of current Chromium-based browsers, such asNot_A Brand, and of older versions, such asNot A;Brandor"Not\A;Brand.Bitness/DecodedBitness,Wow64,FormFactors/DecodedFormFactorson the record and the view.Architecturealso requestsSec-CH-UA-WoW64,DevicealsoSec-CH-UA-Form-Factors. The new optionFullVersionListrequestsSec-CH-UA-Full-Version-List.DecodeStructuredBooleanandDecodeStructuredStringList. An internalStructuredFieldReaderimplements the RFC 9651 parsing of strings, booleans, lists and parameters;DecodeStructuredStringuses it with unchanged results.Decoded*properties of theHttpClientHintsrecord decode on the first access and return the same result afterwards.GetClientHints(HttpContext)and the feature return one record per request. Record equality andwithexpressions are not affected. The view still decodes on every access.CriticalsetsCritical-CHand adds the hints toAccept-CHandVary.Varyadds all requested hints toVary, appended to an existing header once per response.The
Accept-CHmiddleware stays async, as decided in b8aa25b.Performance of the brand lists
ReadDecodedBrandLists(two lists, three brands each)List(a list has at most one member more than commas)SearchValueslookup for the first character of a keyA vectorized search for the end of a string was measured as well (285 ns) and is not used. Reading both lists again from the snapshot of the request takes 10 ns and allocates nothing. The field for the decoded values adds 16 B to the record (104 B → 120 B).
Review fixes
IsGreasemissed the GREASE forms of older Chromium versions.NotABrandwith any of()-./:;=?_"\around them.Accept-CH).Varywas appended again when the pipeline ran again for the same response (UseStatusCodePagesWithReExecute).Packages, CI and release notes
EnablePackageValidation). CI packs in every build, so pull requests are validated too.dotnet testmerges keeps the hits of only one test project per package.eng/Assert-CodeCoverage.ps1reads every report. With the old gate, this PR showed 83 % line coverage for the core package although its own tests cover 100 %.main.pr-labeler.ymlruns it onpull_request_targetwithdisable-releaser. Every pull request gets one category label from the Conventional Commits type in its title;type!:getsbreaking-change, a new category listed first. The rules were checked with JavaScript regular expressions against the titles of feat: add optional IHttpClientHintsFeature middleware, enforce 100% coverage #22 to feat!: 4.0 Client Hints API: data-minimizing defaults, brand lists, Critical-CH and Vary, package validation #25 and typical Dependabot titles. The workflow runs onpull_request_target, so it takes effect after this PR is merged; the labels of chore: deterministic packages, package metadata, CI checks, Dependabot and security policy #24 and feat!: 4.0 Client Hints API: data-minimizing defaults, brand lists, Critical-CH and Vary, package validation #25 are set by hand.Verification
dotnet build -c Release: 0 warnings. Each commit builds and passes its tests.dotnet test -c Releasewith coverage: 872 tests passed; line and branch coverage of both packages 100 % with the new gate.win-x64, CIlinux-x64, .NET 8 to 11).dotnet pack -p:Version=4.0.0: package validation passes. Locally the assembly version is 1.0.0 without NBGV, which validation rejects (CP0003); CI builds with the NBGV version.dotnet format --verify-no-changes: no changes.Benchmarks (.NET 11, same command as in the readme)
GetClientHintsFromHeadersGetClientHintsFromContextUncachedUseHttpClientHintsReadDecodedBrandLists(new)ReadDecodedBrandListsFromCachedSnapshot(new)UseHttpClientHintsWithCriticalAndVary(new)The snapshot reads three more headers (
Sec-CH-UA-Bitness,Sec-CH-UA-WoW64,Sec-CH-UA-Form-Factors) and has three more fields and the field for the decoded values.UseHttpClientHintsno longer setsAccept-CH-Lifetimein the benchmark.