using System.Threading;
using System.Threading.Tasks;
-namespace System.Net.Http.Functional.Tests
+namespace System.Net.Test.Common
{
/// <summary>
/// Provides a test-only HTTP proxy. Handles multiple connections/requests and CONNECT tunneling for HTTPS
{
byte[] buffer = new byte[8000];
int bytesRead;
- while ((bytesRead = await clientStream.ReadAsync(buffer)) > 0)
+ while ((bytesRead = await clientStream.ReadAsync(buffer, 0, buffer.Length)) > 0)
{
await serverStream.WriteAsync(buffer, 0, bytesRead);
}
{
byte[] buffer = new byte[8000];
int bytesRead;
- while ((bytesRead = await serverStream.ReadAsync(buffer)) > 0)
+ while ((bytesRead = await serverStream.ReadAsync(buffer, 0, buffer.Length)) > 0)
{
await clientStream.WriteAsync(buffer, 0, bytesRead);
}
<Compile Include="$(CommonTestPath)\System\Net\VerboseTestLogging.cs">
<Link>Common\System\Net\VerboseTestLogging.cs</Link>
</Compile>
+ <Compile Include="$(CommonTestPath)\System\Net\Http\LoopbackProxyServer.cs">
+ <Link>Common\System\Net\Http\LoopbackProxyServer.cs</Link>
+ </Compile>
<Compile Include="$(CommonTestPath)\System\Net\Http\LoopbackServer.cs">
<Link>Common\System\Net\Http\LoopbackServer.cs</Link>
</Compile>
<Compile Include="HttpProtocolTests.cs" />
<Compile Include="HttpRequestMessageTest.cs" />
<Compile Include="HttpResponseMessageTest.cs" />
- <Compile Include="LoopbackProxyServer.cs" />
<Compile Include="MessageProcessingHandlerTest.cs" />
<Compile Include="MultipartContentTest.cs" />
<Compile Include="MultipartFormDataContentTest.cs" />
{
public ConnectTest(ITestOutputHelper output) : base(output) { }
- [OuterLoop] // TODO: Issue #11345
+ [OuterLoop("Uses external servers")]
[ConditionalTheory(nameof(WebSocketsSupported)), MemberData(nameof(UnavailableWebSocketServers))]
public async Task ConnectAsync_NotWebSocketServer_ThrowsWebSocketExceptionWithMessage(Uri server, string exceptionMessage, WebSocketError errorCode)
{
}
}
- [OuterLoop] // TODO: Issue #11345
+ [OuterLoop("Uses external servers")]
[ConditionalTheory(nameof(WebSocketsSupported)), MemberData(nameof(EchoServers))]
public async Task EchoBinaryMessage_Success(Uri server)
{
await WebSocketHelper.TestEcho(server, WebSocketMessageType.Binary, TimeOutMilliseconds, _output);
}
- [OuterLoop] // TODO: Issue #11345
+ [OuterLoop("Uses external servers")]
[ConditionalTheory(nameof(WebSocketsSupported)), MemberData(nameof(EchoServers))]
public async Task EchoTextMessage_Success(Uri server)
{
await WebSocketHelper.TestEcho(server, WebSocketMessageType.Text, TimeOutMilliseconds, _output);
}
- [OuterLoop] // TODO: Issue #11345
+ [OuterLoop("Uses external servers")]
[ConditionalTheory(nameof(WebSocketsSupported)), MemberData(nameof(EchoHeadersServers))]
public async Task ConnectAsync_AddCustomHeaders_Success(Uri server)
{
}
[ActiveIssue(18784, TargetFrameworkMonikers.NetFramework)]
- [OuterLoop]
+ [OuterLoop("Uses external servers")]
[ConditionalTheory(nameof(WebSocketsSupported))]
public async Task ConnectAsync_AddHostHeader_Success()
{
}
}
- [OuterLoop] // TODO: Issue #11345
+ [OuterLoop("Uses external servers")]
[ConditionalTheory(nameof(WebSocketsSupported)), MemberData(nameof(EchoHeadersServers))]
public async Task ConnectAsync_CookieHeaders_Success(Uri server)
{
}
}
- [OuterLoop] // TODO: Issue #11345
+ [OuterLoop("Uses external servers")]
[ConditionalTheory(nameof(WebSocketsSupported)), MemberData(nameof(EchoServers))]
public async Task ConnectAsync_PassNoSubProtocol_ServerRequires_ThrowsWebSocketException(Uri server)
{
}
}
- [OuterLoop] // TODO: Issue #11345
+ [OuterLoop("Uses external servers")]
[ConditionalTheory(nameof(WebSocketsSupported)), MemberData(nameof(EchoServers))]
public async Task ConnectAsync_PassMultipleSubProtocols_ServerRequires_ConnectionUsesAgreedSubProtocol(Uri server)
{
Assert.True(await LoopbackHelper.WebSocketHandshakeAsync(connection));
}), new LoopbackServer.Options { WebSocketEndpoint = true });
}
+
+ [OuterLoop("Uses external servers")]
+ [ConditionalTheory(nameof(WebSocketsSupported)), MemberData(nameof(EchoServers))]
+ public async Task ConnectAndCloseAsync_UseProxyServer_ExpectedClosedState(Uri server)
+ {
+ using (var cws = new ClientWebSocket())
+ using (var cts = new CancellationTokenSource(TimeOutMilliseconds))
+ using (LoopbackProxyServer proxyServer = LoopbackProxyServer.Create())
+ {
+ cws.Options.Proxy = new WebProxy(proxyServer.Uri);
+ await cws.ConnectAsync(server, cts.Token);
+
+ string expectedCloseStatusDescription = "Client close status";
+ await cws.CloseAsync(WebSocketCloseStatus.NormalClosure, expectedCloseStatusDescription, cts.Token);
+
+ Assert.Equal(WebSocketState.Closed, cws.State);
+ Assert.Equal(WebSocketCloseStatus.NormalClosure, cws.CloseStatus);
+ Assert.Equal(expectedCloseStatusDescription, cws.CloseStatusDescription);
+ }
+ }
}
}