-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
6 changed files
with
640 additions
and
14 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
src/Servers/Kestrel/shared/test/TransportTestHelpers/IHostPortExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Globalization; | ||
using System.Linq; | ||
using Microsoft.AspNetCore.Hosting.Server; | ||
using Microsoft.AspNetCore.Hosting.Server.Features; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
|
||
namespace Microsoft.AspNetCore.Hosting | ||
{ | ||
public static class IHostPortExtensions | ||
{ | ||
public static int GetPort(this IHost host) | ||
{ | ||
return host.GetPorts().First(); | ||
} | ||
|
||
public static IEnumerable<int> GetPorts(this IHost host) | ||
{ | ||
return host.GetUris() | ||
.Select(u => u.Port); | ||
} | ||
|
||
public static IEnumerable<Uri> GetUris(this IHost host) | ||
{ | ||
return host.Services.GetRequiredService<IServer>().Features.Get<IServerAddressesFeature>().Addresses | ||
.Select(a => new Uri(a)); | ||
} | ||
|
||
public static string MakeUrl(this IHost host, string scheme) | ||
{ | ||
return $"{scheme}://127.0.0.1:{host.GetPort().ToString(CultureInfo.InvariantCulture)}/"; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.