Skip to content

Remove unsafe code from Http KnownHeaders #114757

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 2 commits into from
Apr 19, 2025

Conversation

MihaZupan
Copy link
Member

This also gets rid of the redundant bounds checks for the char variant.
For byte the codegen is the same.

@MihaZupan MihaZupan added this to the 10.0.0 milestone Apr 17, 2025
@MihaZupan MihaZupan self-assigned this Apr 17, 2025
@Copilot Copilot AI review requested due to automatic review settings April 17, 2025 01:54
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 removes unsafe code from the KnownHeaders implementation and simplifies header candidate lookup by eliminating the redundant IHeaderNameAccessor interface and related types. The key changes are:

  • Removal of the unsafe IHeaderNameAccessor interface and its implementations.
  • Refactoring of GetCandidate to work with ReadOnlySpan and a new generic constraint.
  • Exposure of TryGetKnownHeader methods as public.
Comments suppressed due to low confidence (2)

src/libraries/System.Net.Http/src/System/Net/Http/Headers/KnownHeaders.cs:125

  • Ensure that both 'char' and 'byte' types implement INumberBase so the new generic constraint works as expected when using GetCandidate.
private static KnownHeader? GetCandidate<T>(ReadOnlySpan<T> key)

src/libraries/System.Net.Http/src/System/Net/Http/Headers/KnownHeaders.cs:395

  • Verify that removing the fixed block for the ReadOnlySpan overload does not introduce any unintended performance regressions or memory safety issues.
KnownHeader? candidate = GetCandidate(name);

Copy link
Contributor

Tagging subscribers to this area: @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

@MihaZupan
Copy link
Member Author

/ba-g test failures are #114769 and #114790

@MihaZupan MihaZupan merged commit 2db2821 into dotnet:main Apr 19, 2025
77 of 85 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants