From fdcadafa44f624ae756c5b1b8307ebf0cbc2435b Mon Sep 17 00:00:00 2001 From: rabdulatif Date: Fri, 4 Oct 2024 19:14:03 +0500 Subject: [PATCH 1/2] Updated GetScheme method in SwaggerServiceDiscoveryProvider --- .../SwaggerServiceDiscoveryProvider.cs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/MMLib.SwaggerForOcelot/ServiceDiscovery/SwaggerServiceDiscoveryProvider.cs b/src/MMLib.SwaggerForOcelot/ServiceDiscovery/SwaggerServiceDiscoveryProvider.cs index 2769c73..9385f12 100644 --- a/src/MMLib.SwaggerForOcelot/ServiceDiscovery/SwaggerServiceDiscoveryProvider.cs +++ b/src/MMLib.SwaggerForOcelot/ServiceDiscovery/SwaggerServiceDiscoveryProvider.cs @@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Options; using MMLib.SwaggerForOcelot.Configuration; +using Ocelot.Configuration; using Ocelot.Configuration.Builder; using Ocelot.Configuration.Creator; using Ocelot.Configuration.File; @@ -13,6 +14,7 @@ using System; using System.Linq; using System.Threading.Tasks; +using RouteOptions = MMLib.SwaggerForOcelot.Configuration.RouteOptions; namespace MMLib.SwaggerForOcelot.ServiceDiscovery { @@ -106,12 +108,8 @@ private async Task GetSwaggerUri(SwaggerEndPointConfig endPoint, RouteOptio throw new InvalidOperationException(GetErrorMessage(endPoint)); } - var builder = new UriBuilder(GetScheme(service, route), service.DownstreamHost, service.DownstreamPort); - if (builder.Scheme.IsNullOrEmpty()) - { - builder.Scheme = conf?.Scheme ?? "http"; - } - builder.Scheme = conf?.Scheme ?? "http"; + var builder = new UriBuilder(GetScheme(service, route, conf), service.DownstreamHost, + service.DownstreamPort); if (endPoint.Service.Path.IsNullOrEmpty()) { @@ -126,7 +124,7 @@ private async Task GetSwaggerUri(SwaggerEndPointConfig endPoint, RouteOptio return builder.Uri; } - private string GetScheme(ServiceHostAndPort service, RouteOptions route) + private string GetScheme(ServiceHostAndPort service, RouteOptions route, ServiceProviderConfiguration conf) => (route is not null && !route.DownstreamScheme.IsNullOrEmpty()) ? route.DownstreamScheme : !service.Scheme.IsNullOrEmpty() @@ -136,7 +134,7 @@ private string GetScheme(ServiceHostAndPort service, RouteOptions route) { 443 => Uri.UriSchemeHttps, 80 => Uri.UriSchemeHttp, - _ => string.Empty, + _ => conf?.Scheme ?? "http", }; public static string? ServiceProviderType { get; set; } From 559b556446f265d5289fb84909f2935304c9baf8 Mon Sep 17 00:00:00 2001 From: rabdulatif Date: Fri, 4 Oct 2024 19:19:38 +0500 Subject: [PATCH 2/2] Updated --- .../ServiceDiscovery/SwaggerServiceDiscoveryProvider.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MMLib.SwaggerForOcelot/ServiceDiscovery/SwaggerServiceDiscoveryProvider.cs b/src/MMLib.SwaggerForOcelot/ServiceDiscovery/SwaggerServiceDiscoveryProvider.cs index 9385f12..d26dc8a 100644 --- a/src/MMLib.SwaggerForOcelot/ServiceDiscovery/SwaggerServiceDiscoveryProvider.cs +++ b/src/MMLib.SwaggerForOcelot/ServiceDiscovery/SwaggerServiceDiscoveryProvider.cs @@ -134,7 +134,7 @@ private string GetScheme(ServiceHostAndPort service, RouteOptions route, Service { 443 => Uri.UriSchemeHttps, 80 => Uri.UriSchemeHttp, - _ => conf?.Scheme ?? "http", + _ => conf?.Scheme ?? "http" }; public static string? ServiceProviderType { get; set; }