Skip to content
This repository was archived by the owner on Dec 18, 2018. It is now read-only.

Commit a1af23e

Browse files
author
Cesar Blum Silveira
committed
Partially address PR feedback.
1 parent 5872990 commit a1af23e

File tree

6 files changed

+25
-75
lines changed

6 files changed

+25
-75
lines changed

src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public void Start<TContext>(IHttpApplication<TContext> application)
117117

118118
if (parsedAddress.Host.Equals("localhost", StringComparison.OrdinalIgnoreCase))
119119
{
120-
var exceptions = new List<Exception>();
120+
var exceptionCount = 0;
121121
var originalHost = parsedAddress.Host;
122122

123123
try
@@ -129,7 +129,7 @@ public void Start<TContext>(IHttpApplication<TContext> application)
129129
catch (UvException ex) when (ex.StatusCode != Constants.EADDRINUSE)
130130
{
131131
_logger.LogWarning(0, ex, $"Unable to bind {address} to loopback IPv4 address.");
132-
exceptions.Add(ex);
132+
exceptionCount++;
133133
}
134134

135135
try
@@ -141,10 +141,10 @@ public void Start<TContext>(IHttpApplication<TContext> application)
141141
catch (UvException ex) when (ex.StatusCode != Constants.EADDRINUSE)
142142
{
143143
_logger.LogWarning(0, ex, $"Unable to bind {address} to loopback IPv6 address.");
144-
exceptions.Add(ex);
144+
exceptionCount++;
145145
}
146146

147-
if (exceptions.Count == 2)
147+
if (exceptionCount == 2)
148148
{
149149
throw new InvalidOperationException("Binding to localhost failed to bind to any loopback address.");
150150
}

test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
5-
using System.Collections.Generic;
65
using System.Linq;
76
using System.Net;
87
using System.Net.Http;
@@ -13,8 +12,8 @@
1312
using Microsoft.AspNetCore.Hosting.Server.Features;
1413
using Microsoft.AspNetCore.Http;
1514
using Microsoft.AspNetCore.Http.Extensions;
15+
using Microsoft.AspNetCore.Server.Kestrel.Networking;
1616
using Microsoft.AspNetCore.Testing.xunit;
17-
using Microsoft.Extensions.Configuration;
1817
using Xunit;
1918

2019
namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
@@ -52,16 +51,9 @@ public async Task RegisterAddresses_IPv6ScopeId_Success(string addressInput, Fun
5251

5352
public async Task RegisterAddresses_Success(string addressInput, Func<IServerAddressesFeature, string[]> testUrls)
5453
{
55-
var config = new ConfigurationBuilder()
56-
.AddInMemoryCollection(new Dictionary<string, string>
57-
{
58-
{ "server.urls", addressInput }
59-
})
60-
.Build();
61-
6254
var hostBuilder = new WebHostBuilder()
63-
.UseConfiguration(config)
6455
.UseKestrel()
56+
.UseUrls(addressInput)
6557
.Configure(ConfigureEchoAddress);
6658

6759
using (var host = hostBuilder.Build())
@@ -104,21 +96,15 @@ private void ThrowsWhenBindingLocalhostToAddressInUse(AddressFamily addressFamil
10496
var port = GetNextPort();
10597
socket.Bind(new IPEndPoint(address, port));
10698

107-
var config = new ConfigurationBuilder()
108-
.AddInMemoryCollection(new Dictionary<string, string>
109-
{
110-
{ "server.urls", $"http://localhost:{port}" }
111-
})
112-
.Build();
113-
11499
var hostBuilder = new WebHostBuilder()
115-
.UseConfiguration(config)
116100
.UseKestrel()
101+
.UseUrls($"http://localhost:{port}")
117102
.Configure(ConfigureEchoAddress);
118103

119104
using (var host = hostBuilder.Build())
120105
{
121-
Assert.Throws<AggregateException>(() => host.Start());
106+
var exception = Assert.Throws<AggregateException>(() => host.Start());
107+
Assert.Contains(exception.InnerExceptions, ex => ex is UvException);
122108
}
123109
}
124110
}

test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/PathBaseTests.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4-
using System.Collections.Generic;
54
using System.Net.Http;
65
using System.Threading.Tasks;
76
using Microsoft.AspNetCore.Builder;
87
using Microsoft.AspNetCore.Hosting;
98
using Microsoft.AspNetCore.Http;
10-
using Microsoft.Extensions.Configuration;
119
using Newtonsoft.Json;
1210
using Newtonsoft.Json.Linq;
1311
using Xunit;
@@ -68,14 +66,9 @@ public Task PathBaseCanHaveUTF8Characters()
6866

6967
private async Task TestPathBase(string registerPathBase, string requestPath, string expectedPathBase, string expectedPath)
7068
{
71-
var config = new ConfigurationBuilder().AddInMemoryCollection(
72-
new Dictionary<string, string> {
73-
{ "server.urls", $"http://localhost:0{registerPathBase}" }
74-
}).Build();
75-
7669
var builder = new WebHostBuilder()
77-
.UseConfiguration(config)
7870
.UseKestrel()
71+
.UseUrls($"http://localhost:0{registerPathBase}")
7972
.Configure(app =>
8073
{
8174
app.Run(async context =>

test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public async Task LargeUpload()
2424
{
2525
var builder = new WebHostBuilder()
2626
.UseKestrel()
27-
.UseUrls($"http://localhost:0/")
27+
.UseUrls("http://localhost:0/")
2828
.Configure(app =>
2929
{
3030
app.Run(async context =>
@@ -73,7 +73,7 @@ public async Task LargeMultipartUpload()
7373
{
7474
var builder = new WebHostBuilder()
7575
.UseKestrel()
76-
.UseUrls($"http://localhost:0/")
76+
.UseUrls("http://localhost:0/")
7777
.Configure(app =>
7878
{
7979
app.Run(async context =>
@@ -118,18 +118,20 @@ public async Task LargeMultipartUpload()
118118
}
119119

120120
[Theory]
121-
[InlineData("127.0.0.1", "127.0.0.1")]
122-
[InlineData("localhost", "127.0.0.1")]
123-
public Task RemoteIPv4Address(string requestAddress, string expectAddress)
121+
[InlineData("127.0.0.1", "127.0.0.1", "127.0.0.1")]
122+
[InlineData("localhost", "127.0.0.1", "127.0.0.1")]
123+
public Task RemoteIPv4Address(string registerAddress, string requestAddress, string expectAddress)
124124
{
125-
return TestRemoteIPAddress("localhost", requestAddress, expectAddress);
125+
return TestRemoteIPAddress(registerAddress, requestAddress, expectAddress);
126126
}
127127

128-
[ConditionalFact]
128+
[ConditionalTheory]
129129
[IPv6SupportedCondition]
130-
public Task RemoteIPv6Address()
130+
[InlineData("[::1]", "[::1]", "::1")]
131+
[InlineData("localhost", "[::1]", "::1")]
132+
public Task RemoteIPv6Address(string registerAddress, string requestAddress, string expectAddress)
131133
{
132-
return TestRemoteIPAddress("[::1]", "[::1]", "::1");
134+
return TestRemoteIPAddress(registerAddress, requestAddress, expectAddress);
133135
}
134136

135137
[Fact]

test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
5-
using System.Collections.Generic;
65
using System.Linq;
76
using System.Net;
87
using System.Net.Http;
98
using System.Threading.Tasks;
109
using Microsoft.AspNetCore.Builder;
1110
using Microsoft.AspNetCore.Hosting;
1211
using Microsoft.AspNetCore.Http;
13-
using Microsoft.Extensions.Configuration;
1412
using Microsoft.Extensions.Primitives;
1513
using Xunit;
1614

@@ -21,16 +19,9 @@ public class ResponseTests
2119
[Fact]
2220
public async Task LargeDownload()
2321
{
24-
var config = new ConfigurationBuilder()
25-
.AddInMemoryCollection(new Dictionary<string, string>
26-
{
27-
{ "server.urls", $"http://localhost:0/" }
28-
})
29-
.Build();
30-
3122
var hostBuilder = new WebHostBuilder()
32-
.UseConfiguration(config)
3323
.UseKestrel()
24+
.UseUrls("http://localhost:0/")
3425
.Configure(app =>
3526
{
3627
app.Run(async context =>
@@ -80,16 +71,9 @@ public async Task LargeDownload()
8071
[Theory, MemberData(nameof(NullHeaderData))]
8172
public async Task IgnoreNullHeaderValues(string headerName, StringValues headerValue, string expectedValue)
8273
{
83-
var config = new ConfigurationBuilder()
84-
.AddInMemoryCollection(new Dictionary<string, string>
85-
{
86-
{ "server.urls", $"http://localhost:0/" }
87-
})
88-
.Build();
89-
9074
var hostBuilder = new WebHostBuilder()
91-
.UseConfiguration(config)
9275
.UseKestrel()
76+
.UseUrls("http://localhost:0/")
9377
.Configure(app =>
9478
{
9579
app.Run(async context =>
@@ -127,19 +111,12 @@ public async Task IgnoreNullHeaderValues(string headerName, StringValues headerV
127111
[Fact]
128112
public async Task OnCompleteCalledEvenWhenOnStartingNotCalled()
129113
{
130-
var config = new ConfigurationBuilder()
131-
.AddInMemoryCollection(new Dictionary<string, string>
132-
{
133-
{ "server.urls", $"http://localhost:0/" }
134-
})
135-
.Build();
136-
137114
var onStartingCalled = false;
138115
var onCompletedCalled = false;
139116

140117
var hostBuilder = new WebHostBuilder()
141-
.UseConfiguration(config)
142118
.UseKestrel()
119+
.UseUrls("http://localhost:0/")
143120
.Configure(app =>
144121
{
145122
app.Run(context =>

test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ThreadCountTests.cs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
using Microsoft.AspNetCore.Builder;
88
using Microsoft.AspNetCore.Hosting;
99
using Microsoft.AspNetCore.Http;
10-
using Microsoft.Extensions.Configuration;
1110
using Xunit;
1211

1312
namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
@@ -16,19 +15,12 @@ public class ThreadCountTests
1615
{
1716
public async Task ZeroToTenThreads(int threadCount)
1817
{
19-
var config = new ConfigurationBuilder()
20-
.AddInMemoryCollection(new Dictionary<string, string>
21-
{
22-
{ "server.urls", $"http://localhost:0/" }
23-
})
24-
.Build();
25-
2618
var hostBuilder = new WebHostBuilder()
27-
.UseConfiguration(config)
2819
.UseKestrel(options =>
2920
{
3021
options.ThreadCount = threadCount;
3122
})
23+
.UseUrls("http://localhost:0/")
3224
.Configure(app =>
3325
{
3426
app.Run(context =>

0 commit comments

Comments
 (0)