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

Fix fake tunnel failure #568

Merged
merged 1 commit into from
Mar 31, 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
15 changes: 14 additions & 1 deletion src/Titanium.Web.Proxy/RequestHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Sockets;
#if NETCOREAPP2_1
using System.Net.Security;
#endif
Expand Down Expand Up @@ -188,8 +189,20 @@ await clientStreamWriter.WriteResponseAsync(args.HttpClient.Response,
//If prefetch task is available.
if (connection == null && prefetchTask != null)
{
connection = await prefetchTask;
try
{
connection = await prefetchTask;
}
catch (SocketException e)
{
if(e.SocketErrorCode != SocketError.HostNotFound)
{
throw;
}
}

prefetchTask = null;

}

// create a new connection if cache key changes.
Expand Down
29 changes: 29 additions & 0 deletions tests/Titanium.Web.Proxy.IntegrationTests/HttpsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,34 @@ public async Task Can_Handle_Https_Request()
Assert.AreEqual("I am server. I received your greetings.", body);
}

[TestMethod]
public async Task Can_Handle_Https_Fake_Tunnel_Request()
{
var testSuite = new TestSuite();

var server = testSuite.GetServer();
server.HandleRequest((context) =>
{
return context.Response.WriteAsync("I am server. I received your greetings.");
});

var proxy = testSuite.GetProxy();
proxy.BeforeRequest += async (sender, e) =>
{
e.HttpClient.Request.RequestUri = new Uri(server.ListeningHttpUrl);
await Task.FromResult(0);
};

var client = testSuite.GetClient(proxy);

var response = await client.PostAsync(new Uri($"https://{Guid.NewGuid().ToString()}.com"),
new StringContent("hello server. I am a client."));

Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
var body = await response.Content.ReadAsStringAsync();

Assert.AreEqual("I am server. I received your greetings.", body);
}

}
}