Skip to content
This repository was archived by the owner on Jul 9, 2023. It is now read-only.

test fix #644

Merged
merged 1 commit into from
Oct 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion src/Titanium.Web.Proxy/Http2/Hpack/StaticTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static class StaticTable
/// Appendix A: Static Table Definition
/// </summary>
/// <see cref="http://tools.ietf.org/html/rfc7541#appendix-A"/>
private static readonly List<HttpHeader> staticTable = new List<HttpHeader>()
private static readonly List<HttpHeader> staticTable = new List<HttpHeader>
{
/* 1 */
new HttpHeader(":authority", string.Empty),
Expand Down
4 changes: 3 additions & 1 deletion src/Titanium.Web.Proxy/Network/Tcp/TcpConnectionFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,8 @@ private async Task<TcpServerConnection> createServerConnection(string remoteHost
session.TimeLine["Dns Resolved"] = DateTime.Now;
}

Array.Sort(ipAddresses, (x, y) => x.AddressFamily.CompareTo(y.AddressFamily));

for (int i = 0; i < ipAddresses.Length; i++)
{
try
Expand All @@ -319,7 +321,7 @@ private async Task<TcpServerConnection> createServerConnection(string remoteHost
tcpClient.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
}

await tcpClient.ConnectAsync(ipAddresses[i], port);
await tcpClient.ConnectAsync(ipAddress, port);
break;
}
catch (Exception e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public async Task ReverseProxy_GotContinueAndOkResponse()
{
var testSuite = new TestSuite();
var server = testSuite.GetServer();
var continueServer = new HttpContinueServer()
var continueServer = new HttpContinueServer
{
ExpectationResponse = HttpStatusCode.Continue,
ResponseBody = "I am server. I received your greetings."
Expand Down Expand Up @@ -50,7 +50,7 @@ public async Task ReverseProxy_GotExpectationFailedResponse()
{
var testSuite = new TestSuite();
var server = testSuite.GetServer();
var continueServer = new HttpContinueServer() { ExpectationResponse = HttpStatusCode.ExpectationFailed };
var continueServer = new HttpContinueServer { ExpectationResponse = HttpStatusCode.ExpectationFailed };
server.HandleTcpRequest(continueServer.HandleRequest);

var proxy = testSuite.GetReverseProxy();
Expand All @@ -73,7 +73,7 @@ public async Task ReverseProxy_GotNotFoundResponse()
{
var testSuite = new TestSuite();
var server = testSuite.GetServer();
var continueServer = new HttpContinueServer() { ExpectationResponse = HttpStatusCode.NotFound };
var continueServer = new HttpContinueServer { ExpectationResponse = HttpStatusCode.NotFound };
server.HandleTcpRequest(continueServer.HandleRequest);

var proxy = testSuite.GetReverseProxy();
Expand All @@ -96,7 +96,7 @@ public async Task ReverseProxy_BeforeRequestThrows()
{
var testSuite = new TestSuite();
var server = testSuite.GetServer();
var continueServer = new HttpContinueServer() { ExpectationResponse = HttpStatusCode.Continue };
var continueServer = new HttpContinueServer { ExpectationResponse = HttpStatusCode.Continue };
server.HandleTcpRequest(continueServer.HandleRequest);

var dbzEx = new DivideByZeroException("Undefined");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ namespace Titanium.Web.Proxy.IntegrationTests.Helpers
{
class HttpContinueClient
{
private const int waitTimeout = 200;

private static Encoding MsgEncoding = HttpHelper.GetEncodingFromContentType(null);

public async Task<Response> Post(string server, int port, string content)
Expand Down Expand Up @@ -37,7 +39,7 @@ public async Task<Response> Post(string server, int port, string content)
while ((response = HttpMessageParsing.ParseResponse(responseMsg)) == null)
{
var readTask = client.GetStream().ReadAsync(buffer, 0, 1024);
if (!readTask.Wait(200))
if (!readTask.Wait(waitTimeout))
return null;

responseMsg += MsgEncoding.GetString(buffer, 0, readTask.Result);
Expand All @@ -52,7 +54,7 @@ public async Task<Response> Post(string server, int port, string content)
while ((response = HttpMessageParsing.ParseResponse(responseMsg)) == null)
{
var readTask = client.GetStream().ReadAsync(buffer, 0, 1024);
if (!readTask.Wait(200))
if (!readTask.Wait(waitTimeout))
return null;
responseMsg += MsgEncoding.GetString(buffer, 0, readTask.Result);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ internal static Request ParseRequest(string messageText, bool requireBody)
try
{
Request.ParseRequestLine(line, out var method, out var url, out var version);
RequestResponseBase request = new Request()
RequestResponseBase request = new Request
{
Method = method, RequestUriString = url, HttpVersion = version
};
Expand Down Expand Up @@ -69,7 +69,7 @@ internal static Response ParseResponse(string messageText)
try
{
Response.ParseResponseLine(line, out var version, out var status, out var desc);
RequestResponseBase response = new Response()
RequestResponseBase response = new Response
{
HttpVersion = version, StatusCode = status, StatusDescription = desc
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public async Task Smoke_Test_Nested_Proxy_UserData()
{
Assert.AreEqual("Test", session.UserData);

return await Task.FromResult(new Models.ExternalProxy()
return await Task.FromResult(new Models.ExternalProxy
{
HostName = "localhost",
Port = proxy2.ProxyEndPoints[0].Port
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,21 @@ public class TestProxyServer : IDisposable
public TestProxyServer(bool isReverseProxy, ProxyServer upStreamProxy = null)
{
ProxyServer = new ProxyServer();
ProxyEndPoint explicitEndPoint = isReverseProxy ?
var explicitEndPoint = isReverseProxy ?
(ProxyEndPoint)new TransparentProxyEndPoint(IPAddress.Any, 0, true) :
new ExplicitProxyEndPoint(IPAddress.Any, 0, true);

ProxyServer.AddEndPoint(explicitEndPoint);

if (upStreamProxy != null)
{
ProxyServer.UpStreamHttpProxy = new ExternalProxy()
ProxyServer.UpStreamHttpProxy = new ExternalProxy
{
HostName = "localhost",
Port = upStreamProxy.ProxyEndPoints[0].Port
};

ProxyServer.UpStreamHttpsProxy = new ExternalProxy()
ProxyServer.UpStreamHttpsProxy = new ExternalProxy
{
HostName = "localhost",
Port = upStreamProxy.ProxyEndPoints[0].Port
Expand Down
11 changes: 3 additions & 8 deletions tests/Titanium.Web.Proxy.IntegrationTests/Setup/TestServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,9 @@ public TestServer(X509Certificate2 serverCertificate)
.Get<IServerAddressesFeature>()
.Addresses.ToArray();

string httpAddress = addresses[0];
HttpListeningPort = int.Parse(httpAddress.Split(':')[2]);

string httpsAddress = addresses[1];
HttpsListeningPort = int.Parse(httpsAddress.Split(':')[2]);

string tcpAddress = addresses[2];
TcpListeningPort = int.Parse(tcpAddress.Split(':')[2]);
HttpListeningPort = new Uri(addresses[0]).Port;
HttpsListeningPort = new Uri(addresses[1]).Port;
TcpListeningPort = new Uri(addresses[2]).Port;
}

Func<HttpContext, Task> requestHandler = null;
Expand Down