Skip to content

Conversation

ManickaP
Copy link
Member

As noted in the issue, the special-cased error code is used more widely than just for invalid Latin-1. So I'm removing the special casing and leaving the plain WinHttpException there.

Fixes #117391

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 the special-case handling for invalid Latin-1 headers in WinHTTP and always surfaces a WinHttpException using the error code. It also cleans up the related resource string and updates tests to expect the new exception behavior.

  • Remove FormatException branch for ERROR_INVALID_PARAMETER in header APIs
  • Delete the net_http_invalid_header_value resource entry
  • Update existing test to assert on WinHttpException details

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
src/libraries/System.Net.Http.WinHttpHandler/src/System/Net/Http/WinHttpHandler.cs Replace special-cased FormatException with WinHttpException.CreateExceptionUsingLastError in AddRequestHeaders.
src/libraries/System.Net.Http.WinHttpHandler/src/System/Net/Http/WinHttpCookieContainerAdapter.cs Mirror the exception change in ResetCookieRequestHeaders.
src/libraries/System.Net.Http.WinHttpHandler/src/Resources/Strings.resx Remove the net_http_invalid_header_value entry.
src/libraries/Common/tests/System/Net/Http/HttpClientHandlerTest.cs Update test to expect HttpRequestException with inner error code instead of FormatException.
Comments suppressed due to low confidence (1)

src/libraries/System.Net.Http.WinHttpHandler/src/System/Net/Http/WinHttpCookieContainerAdapter.cs:83

  • The new behavior in ResetCookieRequestHeaders always throws a WinHttpException for invalid header values, but there’s no existing test for this scenario. Adding a unit test to cover invalid cookie header handling would ensure this change is validated.
                    throw WinHttpException.CreateExceptionUsingLastError(nameof(Interop.WinHttp.WinHttpAddRequestHeaders));

Copy link
Contributor

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

@ManickaP
Copy link
Member Author

/ba-g #117772

@ManickaP ManickaP merged commit 3e5f80e into dotnet:main Jul 17, 2025
84 of 88 checks passed
@ManickaP ManickaP deleted the winhttp-header branch July 17, 2025 16:36
@github-actions github-actions bot locked and limited conversation to collaborators Aug 17, 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.

WinHttpHandler reports the wrong error message for large headers
2 participants