BenchmarkConfigurationHelpers.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // Copyright (c) .NET Foundation. All rights reserved.
  2. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
  3. using System;
  4. using System.Net;
  5. using Microsoft.AspNetCore.Hosting;
  6. using Microsoft.AspNetCore.Http;
  7. using Microsoft.Extensions.Configuration;
  8. using System.IO.Pipelines;
  9. namespace PlatformBenchmarks
  10. {
  11. public static class BenchmarkConfigurationHelpers
  12. {
  13. public static IPEndPoint CreateIPEndPoint(this IConfiguration config)
  14. {
  15. var url = config["server.urls"] ?? config["urls"];
  16. if (string.IsNullOrEmpty(url))
  17. {
  18. return new IPEndPoint(IPAddress.Loopback, 8080);
  19. }
  20. var address = BindingAddress.Parse(url);
  21. IPAddress ip;
  22. if (string.Equals(address.Host, "localhost", StringComparison.OrdinalIgnoreCase))
  23. {
  24. ip = IPAddress.Loopback;
  25. }
  26. else if (!IPAddress.TryParse(address.Host, out ip))
  27. {
  28. ip = IPAddress.IPv6Any;
  29. }
  30. return new IPEndPoint(ip, address.Port);
  31. }
  32. }
  33. }