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

Commit ef2019e

Browse files
authored
Merge pull request #644 from justcoding121/master
test fix
2 parents 96a8b1b + 5497aa6 commit ef2019e

File tree

8 files changed

+21
-22
lines changed

8 files changed

+21
-22
lines changed

src/Titanium.Web.Proxy/Http2/Hpack/StaticTable.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public static class StaticTable
2828
/// Appendix A: Static Table Definition
2929
/// </summary>
3030
/// <see cref="http://tools.ietf.org/html/rfc7541#appendix-A"/>
31-
private static readonly List<HttpHeader> staticTable = new List<HttpHeader>()
31+
private static readonly List<HttpHeader> staticTable = new List<HttpHeader>
3232
{
3333
/* 1 */
3434
new HttpHeader(":authority", string.Empty),

src/Titanium.Web.Proxy/Network/Tcp/TcpConnectionFactory.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,8 @@ private async Task<TcpServerConnection> createServerConnection(string remoteHost
294294
session.TimeLine["Dns Resolved"] = DateTime.Now;
295295
}
296296

297+
Array.Sort(ipAddresses, (x, y) => x.AddressFamily.CompareTo(y.AddressFamily));
298+
297299
for (int i = 0; i < ipAddresses.Length; i++)
298300
{
299301
try
@@ -319,7 +321,7 @@ private async Task<TcpServerConnection> createServerConnection(string remoteHost
319321
tcpClient.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
320322
}
321323

322-
await tcpClient.ConnectAsync(ipAddresses[i], port);
324+
await tcpClient.ConnectAsync(ipAddress, port);
323325
break;
324326
}
325327
catch (Exception e)

tests/Titanium.Web.Proxy.IntegrationTests/ExpectContinueTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public async Task ReverseProxy_GotContinueAndOkResponse()
2222
{
2323
var testSuite = new TestSuite();
2424
var server = testSuite.GetServer();
25-
var continueServer = new HttpContinueServer()
25+
var continueServer = new HttpContinueServer
2626
{
2727
ExpectationResponse = HttpStatusCode.Continue,
2828
ResponseBody = "I am server. I received your greetings."
@@ -50,7 +50,7 @@ public async Task ReverseProxy_GotExpectationFailedResponse()
5050
{
5151
var testSuite = new TestSuite();
5252
var server = testSuite.GetServer();
53-
var continueServer = new HttpContinueServer() { ExpectationResponse = HttpStatusCode.ExpectationFailed };
53+
var continueServer = new HttpContinueServer { ExpectationResponse = HttpStatusCode.ExpectationFailed };
5454
server.HandleTcpRequest(continueServer.HandleRequest);
5555

5656
var proxy = testSuite.GetReverseProxy();
@@ -73,7 +73,7 @@ public async Task ReverseProxy_GotNotFoundResponse()
7373
{
7474
var testSuite = new TestSuite();
7575
var server = testSuite.GetServer();
76-
var continueServer = new HttpContinueServer() { ExpectationResponse = HttpStatusCode.NotFound };
76+
var continueServer = new HttpContinueServer { ExpectationResponse = HttpStatusCode.NotFound };
7777
server.HandleTcpRequest(continueServer.HandleRequest);
7878

7979
var proxy = testSuite.GetReverseProxy();
@@ -96,7 +96,7 @@ public async Task ReverseProxy_BeforeRequestThrows()
9696
{
9797
var testSuite = new TestSuite();
9898
var server = testSuite.GetServer();
99-
var continueServer = new HttpContinueServer() { ExpectationResponse = HttpStatusCode.Continue };
99+
var continueServer = new HttpContinueServer { ExpectationResponse = HttpStatusCode.Continue };
100100
server.HandleTcpRequest(continueServer.HandleRequest);
101101

102102
var dbzEx = new DivideByZeroException("Undefined");

tests/Titanium.Web.Proxy.IntegrationTests/Helpers/HttpContinueClient.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ namespace Titanium.Web.Proxy.IntegrationTests.Helpers
99
{
1010
class HttpContinueClient
1111
{
12+
private const int waitTimeout = 200;
13+
1214
private static Encoding MsgEncoding = HttpHelper.GetEncodingFromContentType(null);
1315

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

4345
responseMsg += MsgEncoding.GetString(buffer, 0, readTask.Result);
@@ -52,7 +54,7 @@ public async Task<Response> Post(string server, int port, string content)
5254
while ((response = HttpMessageParsing.ParseResponse(responseMsg)) == null)
5355
{
5456
var readTask = client.GetStream().ReadAsync(buffer, 0, 1024);
55-
if (!readTask.Wait(200))
57+
if (!readTask.Wait(waitTimeout))
5658
return null;
5759
responseMsg += MsgEncoding.GetString(buffer, 0, readTask.Result);
5860
}

tests/Titanium.Web.Proxy.IntegrationTests/Helpers/HttpMessageParsing.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ internal static Request ParseRequest(string messageText, bool requireBody)
2424
try
2525
{
2626
Request.ParseRequestLine(line, out var method, out var url, out var version);
27-
RequestResponseBase request = new Request()
27+
RequestResponseBase request = new Request
2828
{
2929
Method = method, RequestUriString = url, HttpVersion = version
3030
};
@@ -69,7 +69,7 @@ internal static Response ParseResponse(string messageText)
6969
try
7070
{
7171
Response.ParseResponseLine(line, out var version, out var status, out var desc);
72-
RequestResponseBase response = new Response()
72+
RequestResponseBase response = new Response
7373
{
7474
HttpVersion = version, StatusCode = status, StatusDescription = desc
7575
};

tests/Titanium.Web.Proxy.IntegrationTests/NestedProxyTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public async Task Smoke_Test_Nested_Proxy_UserData()
6161
{
6262
Assert.AreEqual("Test", session.UserData);
6363

64-
return await Task.FromResult(new Models.ExternalProxy()
64+
return await Task.FromResult(new Models.ExternalProxy
6565
{
6666
HostName = "localhost",
6767
Port = proxy2.ProxyEndPoints[0].Port

tests/Titanium.Web.Proxy.IntegrationTests/Setup/TestProxyServer.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,21 @@ public class TestProxyServer : IDisposable
1818
public TestProxyServer(bool isReverseProxy, ProxyServer upStreamProxy = null)
1919
{
2020
ProxyServer = new ProxyServer();
21-
ProxyEndPoint explicitEndPoint = isReverseProxy ?
21+
var explicitEndPoint = isReverseProxy ?
2222
(ProxyEndPoint)new TransparentProxyEndPoint(IPAddress.Any, 0, true) :
2323
new ExplicitProxyEndPoint(IPAddress.Any, 0, true);
2424

2525
ProxyServer.AddEndPoint(explicitEndPoint);
2626

2727
if (upStreamProxy != null)
2828
{
29-
ProxyServer.UpStreamHttpProxy = new ExternalProxy()
29+
ProxyServer.UpStreamHttpProxy = new ExternalProxy
3030
{
3131
HostName = "localhost",
3232
Port = upStreamProxy.ProxyEndPoints[0].Port
3333
};
3434

35-
ProxyServer.UpStreamHttpsProxy = new ExternalProxy()
35+
ProxyServer.UpStreamHttpsProxy = new ExternalProxy
3636
{
3737
HostName = "localhost",
3838
Port = upStreamProxy.ProxyEndPoints[0].Port

tests/Titanium.Web.Proxy.IntegrationTests/Setup/TestServer.cs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,9 @@ public TestServer(X509Certificate2 serverCertificate)
6262
.Get<IServerAddressesFeature>()
6363
.Addresses.ToArray();
6464

65-
string httpAddress = addresses[0];
66-
HttpListeningPort = int.Parse(httpAddress.Split(':')[2]);
67-
68-
string httpsAddress = addresses[1];
69-
HttpsListeningPort = int.Parse(httpsAddress.Split(':')[2]);
70-
71-
string tcpAddress = addresses[2];
72-
TcpListeningPort = int.Parse(tcpAddress.Split(':')[2]);
65+
HttpListeningPort = new Uri(addresses[0]).Port;
66+
HttpsListeningPort = new Uri(addresses[1]).Port;
67+
TcpListeningPort = new Uri(addresses[2]).Port;
7368
}
7469

7570
Func<HttpContext, Task> requestHandler = null;

0 commit comments

Comments
 (0)