Skip to content

Commit

Permalink
Remove an approximate two second delay in response to the first reque…
Browse files Browse the repository at this point in the history
…st from a new socket connection, only occuring on some Windows 10 machines.

A side-effect of this fix is that is also allows connections to IPv6 addresses.
  • Loading branch information
benagain committed Mar 21, 2021
1 parent 2fb0f92 commit 57e3ee3
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/WireMock.Net/Owin/AspNetCoreSelfHost.NETStandard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ private static void SetHttpsAndUrls(KestrelServerOptions kestrelOptions, IWireMo
{
if (urlDetail.IsHttps)
{
kestrelOptions.Listen(System.Net.IPAddress.Any, urlDetail.Port, listenOptions =>
kestrelOptions.ListenAnyIP(urlDetail.Port, listenOptions =>
{
if (wireMockMiddlewareOptions.CustomCertificateDefined)
{
Expand All @@ -45,7 +45,7 @@ private static void SetHttpsAndUrls(KestrelServerOptions kestrelOptions, IWireMo
}
else
{
kestrelOptions.Listen(System.Net.IPAddress.Any, urlDetail.Port);
kestrelOptions.ListenAnyIP(urlDetail.Port);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/WireMock.Net/Owin/AspNetCoreSelfHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ private Task RunHost(CancellationToken token)

foreach (string address in addresses)
{
Urls.Add(address.Replace("0.0.0.0", "localhost"));
Urls.Add(address.Replace("0.0.0.0", "localhost").Replace("[::]", "localhost"));

PortUtils.TryExtract(address, out bool isHttps, out string protocol, out string host, out int port);
Ports.Add(port);
Expand Down
46 changes: 46 additions & 0 deletions test/WireMock.Net.Tests/WireMockServerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -305,5 +305,51 @@ public async Task WireMockServer_Should_SupportRequestGZipAndDeflate(string cont

server.Stop();
}

#if !NET452
[Fact]
public async Task WireMockServer_Should_respond_to_ipv4_loopback()
{
// Assign
var server = WireMockServer.Start();

server
.Given(Request.Create()
.WithPath("/*"))
.RespondWith(Response.Create()
.WithStatusCode(200)
.WithBody("from ipv4 loopback"));

// Act
var response = await new HttpClient().GetStringAsync($"http://127.0.0.1:{server.Ports[0]}/foo");

// Assert
Check.That(response).IsEqualTo("from ipv4 loopback");

server.Stop();
}

[Fact]
public async Task WireMockServer_Should_respond_to_ipv6_loopback()
{
// Assign
var server = WireMockServer.Start();

server
.Given(Request.Create()
.WithPath("/*"))
.RespondWith(Response.Create()
.WithStatusCode(200)
.WithBody("from ipv6 loopback"));

// Act
var response = await new HttpClient().GetStringAsync($"http://[::1]:{server.Ports[0]}/foo");

// Assert
Check.That(response).IsEqualTo("from ipv6 loopback");

server.Stop();
}
#endif
}
}

0 comments on commit 57e3ee3

Please sign in to comment.