Skip to content

Conversation

MihaZupan
Copy link
Member

Closes #63750

We have a set of known header names and values that allows us to avoid materializing strings for response headers. This PR expands that list.

Not trying to be perfect here, this is just an easy way to avoid some allocations.
E.g. we were missing some basic cases like Content-Type: text/javascript, Accept-Ranges: bytes, or Connection: keep-alive.

The real change is just 3ab3770

@MihaZupan MihaZupan added this to the 10.0.0 milestone Jul 23, 2025
@MihaZupan MihaZupan self-assigned this Jul 23, 2025
@Copilot Copilot AI review requested due to automatic review settings July 23, 2025 17:16
Copy link
Contributor

@Copilot Copilot AI left a comment

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 expands the set of known HTTP header names and values to optimize string allocation avoidance in response header processing. The changes add more common header values (like text/javascript, Accept-Ranges: bytes, Connection: keep-alive) to the pre-allocated string pools, reducing memory allocations during HTTP processing.

Key changes:

  • Added 3 new known header names: Cross-Origin-Resource-Policy, Timing-Allow-Origin, and X-Served-By
  • Expanded known values for existing headers with commonly-used values
  • Updated Content-Type optimizations to handle more media types and charset variations

Reviewed Changes

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

Show a summary per file
File Description
KnownHeadersTest.cs Added test cases for new known headers and Content-Type values, removed X-Frame-Options test cases
QPackStaticTable.cs Updated reference to use KnownHeaders.TimingAllowOrigin instead of string literal
KnownHeaders.cs Added new header definitions, expanded known values arrays, updated constructor calls to use collection expressions
KnownHeader.cs Simplified constructor overload to include knownValues parameter
HeaderDescriptor.cs Enhanced Content-Type value optimization with additional media types and charset combinations
Comments suppressed due to low confidence (1)

src/libraries/System.Net.Http/tests/UnitTests/Headers/KnownHeadersTest.cs:223

  • The removal of X-Frame-Options test cases (DENY and SAMEORIGIN) reduces test coverage for this header's known values. These test cases should be retained to ensure the X-Frame-Options header values are properly validated.
        [InlineData("X-Content-Type-Options", "nosniff")]

@MihaZupan
Copy link
Member Author

/ba-g Build analysis isn't picking up the duplicate WASM queue timeouts

@MihaZupan MihaZupan merged commit 831523d into dotnet:main Jul 24, 2025
81 of 87 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Aug 24, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

We could improve the list of known headers & values
2 participants