Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
PR feedback
  • Loading branch information
MihaZupan committed Jul 9, 2021
commit da8844d6cf83d6318a02c9767e838b20f4edc4cf
Original file line number Diff line number Diff line change
Expand Up @@ -1950,5 +1950,23 @@ public async Task GetAsync_InvalidUrl_ExpectedExceptionThrown()
await Assert.ThrowsAsync<HttpRequestException>(() => client.GetStringAsync(invalidUri));
}
}

// HttpRequestMessage ctor guards against such Uris before .NET 6. We allow passing relative/unknown Uris to BrowserHttpHandler.
public static bool InvalidRequestUriTest_IsSupported => PlatformDetection.IsNotNetFramework && PlatformDetection.IsNotBrowser;

[ConditionalFact(nameof(InvalidRequestUriTest_IsSupported))]
public async Task SendAsync_InvalidRequestUri_Throws()
{
using var invoker = new HttpMessageInvoker(CreateHttpClientHandler());

var request = new HttpRequestMessage(HttpMethod.Get, (Uri)null);
await Assert.ThrowsAsync<InvalidOperationException>(() => invoker.SendAsync(request, CancellationToken.None));

request = new HttpRequestMessage(HttpMethod.Get, new Uri("/relative", UriKind.Relative));
await Assert.ThrowsAsync<InvalidOperationException>(() => invoker.SendAsync(request, CancellationToken.None));

request = new HttpRequestMessage(HttpMethod.Get, new Uri("foo://foo.bar"));
await Assert.ThrowsAsync<NotSupportedException>(() => invoker.SendAsync(request, CancellationToken.None));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,6 @@
<value>The '{0}' scheme is not supported.</value>
</data>
<data name="net_http_client_invalid_requesturi" xml:space="preserve">
<value>An invalid request URI was provided. The request URI must either be an absolute URI or BaseAddress must be set.</value>
<value>An invalid request URI was provided. Either the request URI must be an absolute URI or BaseAddress must be set.</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,6 @@ public WinHttpHandlerTest(ITestOutputHelper output)
_output = output;
}

[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotNetFramework))] // HttpRequestMessage ctor guards against such Uris before .NET 6
public async Task SendAsync_InvalidRequestUri_Throws()
{
using var invoker = new HttpMessageInvoker(new WinHttpHandler());

var request = new HttpRequestMessage(HttpMethod.Get, (Uri)null);
await Assert.ThrowsAsync<InvalidOperationException>(() => invoker.SendAsync(request, CancellationToken.None));

request = new HttpRequestMessage(HttpMethod.Get, new Uri("/relative", UriKind.Relative));
await Assert.ThrowsAsync<InvalidOperationException>(() => invoker.SendAsync(request, CancellationToken.None));

request = new HttpRequestMessage(HttpMethod.Get, new Uri("foo://foo.bar"));
await Assert.ThrowsAsync<NotSupportedException>(() => invoker.SendAsync(request, CancellationToken.None));
}

[OuterLoop]
[Fact]
public void SendAsync_SimpleGet_Success()
Expand Down
2 changes: 1 addition & 1 deletion src/libraries/System.Net.Http/src/Resources/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@
<value>The base address must be an absolute URI.</value>
</data>
<data name="net_http_client_invalid_requesturi" xml:space="preserve">
<value>An invalid request URI was provided. The request URI must either be an absolute URI or BaseAddress must be set.</value>
<value>An invalid request URI was provided. Either the request URI must be an absolute URI or BaseAddress must be set.</value>
</data>
<data name="net_http_unsupported_requesturi_scheme" xml:space="preserve">
<value>The '{0}' scheme is not supported.</value>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,6 @@ protected internal sealed override Task<HttpResponseMessage> SendAsync(HttpReque
// if the operation was canceled: We'll set the Task returned to the user to canceled. Passing the
// cancellation token here would result in the continuation task to not be called at all. I.e. we
// would never complete the task returned to the caller of SendAsync().
//
// Always specify TaskScheduler.Default to prevent us from using a user defined TaskScheduler.Current.
//
// Since we're not doing any CPU and/or I/O intensive operations, continue on the same thread.
// This results in better performance since the continuation task doesn't get scheduled by the
// scheduler and there are no context switches required.
}, tcs, CancellationToken.None, TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Default);
}
catch (OperationCanceledException e)
Expand Down