Unverified Commit 9611096d authored by Jehonathan Thomas's avatar Jehonathan Thomas Committed by GitHub

Merge pull request #568 from justcoding121/bugfix/fix-fake-tunnel-failure

Fix fake tunnel failure
parents 48c041e6 ac02c68b
......@@ -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
......@@ -188,8 +189,20 @@ namespace Titanium.Web.Proxy
//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.
......
......@@ -33,5 +33,34 @@ namespace Titanium.Web.Proxy.IntegrationTests
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);
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment