From 5b7e26054c36184d3ab559628e97d5993f8b8f4d Mon Sep 17 00:00:00 2001 From: Kevin Grossmann Date: Thu, 19 Aug 2021 11:16:17 +0200 Subject: [PATCH 1/2] Ignore port when using UpstreamHost option --- .../Middleware/DownstreamRouteFinderMiddleware.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Ocelot/DownstreamRouteFinder/Middleware/DownstreamRouteFinderMiddleware.cs b/src/Ocelot/DownstreamRouteFinder/Middleware/DownstreamRouteFinderMiddleware.cs index 1e8d69cd7..a20a470ee 100644 --- a/src/Ocelot/DownstreamRouteFinder/Middleware/DownstreamRouteFinderMiddleware.cs +++ b/src/Ocelot/DownstreamRouteFinder/Middleware/DownstreamRouteFinderMiddleware.cs @@ -27,7 +27,7 @@ public async Task Invoke(HttpContext httpContext) var upstreamQueryString = httpContext.Request.QueryString.ToString(); - var upstreamHost = httpContext.Request.Headers["Host"]; + var upstreamHost = httpContext.Request.Headers["Host"].ToString().Split(":")[0]; Logger.LogDebug($"Upstream url path is {upstreamUrlPath}"); From 1862beb3d17dd523deb80c29ca8df7670b0a7ba3 Mon Sep 17 00:00:00 2001 From: Raman Maksimchuk Date: Fri, 29 Sep 2023 21:36:59 +0300 Subject: [PATCH 2/2] Update src/Ocelot/DownstreamRouteFinder/Middleware/DownstreamRouteFinderMiddleware.cs --- .../Middleware/DownstreamRouteFinderMiddleware.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Ocelot/DownstreamRouteFinder/Middleware/DownstreamRouteFinderMiddleware.cs b/src/Ocelot/DownstreamRouteFinder/Middleware/DownstreamRouteFinderMiddleware.cs index a20a470ee..678ed7ec2 100644 --- a/src/Ocelot/DownstreamRouteFinder/Middleware/DownstreamRouteFinderMiddleware.cs +++ b/src/Ocelot/DownstreamRouteFinder/Middleware/DownstreamRouteFinderMiddleware.cs @@ -27,7 +27,10 @@ public async Task Invoke(HttpContext httpContext) var upstreamQueryString = httpContext.Request.QueryString.ToString(); - var upstreamHost = httpContext.Request.Headers["Host"].ToString().Split(":")[0]; + var hostHeader = httpContext.Request.Headers["Host"].ToString(); + var upstreamHost = hostHeader.Contains(':') + ? hostHeader.Split(':')[0] + : hostHeader; Logger.LogDebug($"Upstream url path is {upstreamUrlPath}");