Skip to content

Commit 3e5f80e

Browse files
authored
Remove specific exception (#117756)
1 parent 33bc25d commit 3e5f80e

File tree

4 files changed

+4
-24
lines changed

4 files changed

+4
-24
lines changed

src/libraries/Common/tests/System/Net/Http/HttpClientHandlerTest.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2216,14 +2216,13 @@ await LoopbackServerFactory.CreateClientAndServerAsync(async uri =>
22162216
// WinHTTP validates the input before opening connection whereas SocketsHttpHandler opens connection first and validates only when writing to the wire.
22172217
acceptConnection.SetResult(!IsWinHttpHandler);
22182218
var ex = await Assert.ThrowsAnyAsync<Exception>(() => client.SendAsync(request));
2219+
var hrex = Assert.IsType<HttpRequestException>(ex);
22192220
if (IsWinHttpHandler)
22202221
{
2221-
var fex = Assert.IsType<FormatException>(ex);
2222-
Assert.Contains("Latin-1", fex.Message);
2222+
Assert.Contains("Error 87", hrex.InnerException.Message);
22232223
}
22242224
else
22252225
{
2226-
var hrex = Assert.IsType<HttpRequestException>(ex);
22272226
var message = UseVersion == HttpVersion30 ? hrex.InnerException.Message : hrex.Message;
22282227
Assert.Contains("ASCII", message);
22292228
}

src/libraries/System.Net.Http.WinHttpHandler/src/Resources/Strings.resx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,4 @@
135135
<data name="net_http_unsupported_version" xml:space="preserve">
136136
<value>Request version value must be one of 1.0, 1.1, 2.0, or 3.0.</value>
137137
</data>
138-
<data name="net_http_invalid_header_value" xml:space="preserve">
139-
<value>Request headers must be valid Latin-1 characters.</value>
140-
</data>
141138
</root>

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

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,7 @@ public static void ResetCookieRequestHeaders(WinHttpRequestState state, Uri redi
8080
(uint)cookieHeader.Length,
8181
Interop.WinHttp.WINHTTP_ADDREQ_FLAG_ADD))
8282
{
83-
int lastError = Marshal.GetLastWin32Error();
84-
if (lastError == Interop.WinHttp.ERROR_INVALID_PARAMETER)
85-
{
86-
throw new FormatException(SR.net_http_invalid_header_value);
87-
}
88-
else
89-
{
90-
throw WinHttpException.CreateExceptionUsingError(lastError, nameof(Interop.WinHttp.WinHttpAddRequestHeaders));
91-
}
83+
throw WinHttpException.CreateExceptionUsingLastError(nameof(Interop.WinHttp.WinHttpAddRequestHeaders));
9284
}
9385
}
9486
}

src/libraries/System.Net.Http.WinHttpHandler/src/System/Net/Http/WinHttpHandler.cs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -769,15 +769,7 @@ private static void AddRequestHeaders(
769769
(uint)requestHeadersBuffer.Length,
770770
Interop.WinHttp.WINHTTP_ADDREQ_FLAG_ADD))
771771
{
772-
int lastError = Marshal.GetLastWin32Error();
773-
if (lastError == Interop.WinHttp.ERROR_INVALID_PARAMETER)
774-
{
775-
throw new FormatException(SR.net_http_invalid_header_value);
776-
}
777-
else
778-
{
779-
throw WinHttpException.CreateExceptionUsingError(lastError, nameof(Interop.WinHttp.WinHttpAddRequestHeaders));
780-
}
772+
throw WinHttpException.CreateExceptionUsingLastError(nameof(Interop.WinHttp.WinHttpAddRequestHeaders));
781773
}
782774
}
783775

0 commit comments

Comments
 (0)