Skip to content

WinHttpHandler reports the wrong error message for large headers #117391

@MihaZupan

Description

@MihaZupan

int lastError = Marshal.GetLastWin32Error();
if (lastError == Interop.WinHttp.ERROR_INVALID_PARAMETER)
{
throw new FormatException(SR.net_http_invalid_header_value);
}
else
{
throw WinHttpException.CreateExceptionUsingError(lastError, nameof(Interop.WinHttp.WinHttpAddRequestHeaders));
}

<data name="net_http_invalid_header_value" xml:space="preserve">
<value>Request headers must be valid Latin-1 characters.</value>
</data>

Looks like ERROR_INVALID_PARAMETER is thrown in more cases than just non-Latin-1, e.g. sending a header name/value longer than 64 KB.
The error is also reported for a subset of [128-159] (except 129, 141, 143, 144, 157).

Simple fix here might be to just not throw a specialized exception.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions