Skip to content

Improve HTTP header parser recovery performance - #68306

Merged
javiercn merged 1 commit into
mainfrom
fix-68305-header-parser-recovery
Aug 11, 2026
Merged

Improve HTTP header parser recovery performance#68306
javiercn merged 1 commit into
mainfrom
fix-68305-header-parser-recovery

Conversation

@javiercn

@javiercn javiercn commented Aug 9, 2026

Copy link
Copy Markdown
Member

Fixes #68305

Summary

  • report consumed malformed spans from additional HTTP header parser failure paths
  • preserve forgiving-list recovery of subsequent valid values
  • add regression coverage for shared separators, media types, Set-Cookie, and quality values
  • add BenchmarkDotNet coverage through 32,768-character inputs

Validation

  • dotnet test .\src\Http\Headers\test\Microsoft.Net.Http.Headers.Tests.csproj -c Release --no-restore
  • dotnet build .\src\Http\Http\perf\Microbenchmarks\Microsoft.AspNetCore.Http.Microbenchmarks.csproj -c Release --no-restore -p:UseIisNativeAssets=false
  • BenchmarkDotNet validation for HeaderParserListBenchmarks

Avoid revisiting malformed input that header element parsers have already inspected. Add recovery regression tests and BenchmarkDotNet coverage for the affected list parser paths.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI lite review requested due to automatic review settings August 9, 2026 15:46
@javiercn
javiercn requested a review from cincuranet August 9, 2026 15:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves the performance of forgiving (non-strict) HTTP header list parsing by ensuring element parsers report how much malformed input they already inspected, allowing the shared recovery loop to skip past invalid spans in O(1) rather than repeatedly re-scanning the same characters. It also adds targeted regression tests and microbenchmarks to validate both correctness (recovery of subsequent valid values) and performance at realistic worst-case input sizes.

Changes:

  • Propagate “consumed malformed span” lengths from additional failure paths in BaseHeaderParser<T>, MediaTypeHeaderValue, SetCookieHeaderValue, and StringWithQualityHeaderValue.
  • Add regression tests covering recovery of a valid value after malformed separators, media types (missing / / subtype), Set-Cookie (missing =), and invalid quality suffixes.
  • Add BenchmarkDotNet coverage for these scenarios up to 32,768-character inputs.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/Http/Http/perf/Microbenchmarks/HeaderParserListBenchmarks.cs Adds microbenchmarks for key malformed-list recovery scenarios across increasing input sizes.
src/Http/Headers/test/StringWithQualityHeaderValueTest.cs Adds regression test ensuring invalid quality suffix recovery preserves following valid value.
src/Http/Headers/test/SetCookieHeaderValueTest.cs Adds regression test ensuring missing = recovery preserves following valid Set-Cookie.
src/Http/Headers/test/MediaTypeHeaderValueTest.cs Adds regression tests for recovery after missing / and missing subtype patterns.
src/Http/Headers/test/EntityTagHeaderValueTest.cs Adds regression coverage validating separator-skipping recovery avoids repeated parsing work.
src/Http/Headers/src/StringWithQualityHeaderValue.cs Reports consumed malformed span when quality parsing fails after ;.
src/Http/Headers/src/SetCookieHeaderValue.cs Reports consumed malformed span when cookie name is missing =.
src/Http/Headers/src/MediaTypeHeaderValue.cs Reports consumed malformed span for missing / and missing subtype cases via null mediaType signaling.
src/Http/Headers/src/BaseHeaderParser.cs Reports consumed malformed span when list separator/whitespace was scanned before element parsing returns 0.

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

@javiercn
javiercn merged commit 66e8a02 into main Aug 11, 2026
30 checks passed
@javiercn
javiercn deleted the fix-68305-header-parser-recovery branch August 11, 2026 07:54
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-rc1 milestone Aug 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve malformed-value recovery performance in HTTP header list parsers

3 participants