diff --git a/src/Microsoft.Tye.Hosting/HttpProxyService.cs b/src/Microsoft.Tye.Hosting/HttpProxyService.cs index 98e37302..cc22c424 100644 --- a/src/Microsoft.Tye.Hosting/HttpProxyService.cs +++ b/src/Microsoft.Tye.Hosting/HttpProxyService.cs @@ -153,7 +153,7 @@ namespace Microsoft.Tye.Hosting } var uri = new UriBuilder(uris[next].Uri) { - Path = rule.PreservePath ? $"{context.Request.Path}{context.Request.RouteValues["path"]}" : (string)context.Request.RouteValues["path"] ?? "/", + Path = rule.PreservePath ? $"{context.Request.Path}" : (string)context.Request.RouteValues["path"] ?? "/", Query = context.Request.QueryString.Value }; diff --git a/test/E2ETest/TyeRunTests.cs b/test/E2ETest/TyeRunTests.cs index a9e625ed..406500de 100644 --- a/test/E2ETest/TyeRunTests.cs +++ b/test/E2ETest/TyeRunTests.cs @@ -697,6 +697,10 @@ services: Assert.StartsWith("Hello from Application A", await responseA.Content.ReadAsStringAsync()); Assert.StartsWith("Hello from Application B", await responseB.Content.ReadAsStringAsync()); + + // checking preservePath behavior + var responsePreservePath = await client.GetAsync(ingressUri + "/C/test"); + Assert.Contains("Hit path /C/test", await responsePreservePath.Content.ReadAsStringAsync()); }); } diff --git a/test/E2ETest/testassets/generate/apps-with-ingress.1.18.yaml b/test/E2ETest/testassets/generate/apps-with-ingress.1.18.yaml index ae2ce23f..960e19cb 100644 --- a/test/E2ETest/testassets/generate/apps-with-ingress.1.18.yaml +++ b/test/E2ETest/testassets/generate/apps-with-ingress.1.18.yaml @@ -145,6 +145,10 @@ spec: serviceName: appb servicePort: 80 path: /B(/|$)(.*) + - backend: + serviceName: appa + servicePort: 80 + path: /()(C.*) - host: a.example.com http: paths: diff --git a/test/E2ETest/testassets/generate/apps-with-ingress.1.19.yaml b/test/E2ETest/testassets/generate/apps-with-ingress.1.19.yaml index e8cbbe05..70b38979 100644 --- a/test/E2ETest/testassets/generate/apps-with-ingress.1.19.yaml +++ b/test/E2ETest/testassets/generate/apps-with-ingress.1.19.yaml @@ -151,6 +151,13 @@ spec: number: 80 path: /B(/|$)(.*) pathType: Prefix + - backend: + service: + name: appa + port: + number: 80 + path: /()(C.*) + pathType: Prefix - host: a.example.com http: paths: diff --git a/test/E2ETest/testassets/projects/apps-with-ingress/ApplicationA/Startup.cs b/test/E2ETest/testassets/projects/apps-with-ingress/ApplicationA/Startup.cs index 294319e4..0d0e171a 100644 --- a/test/E2ETest/testassets/projects/apps-with-ingress/ApplicationA/Startup.cs +++ b/test/E2ETest/testassets/projects/apps-with-ingress/ApplicationA/Startup.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.IO; using System.Text.Json; using Microsoft.AspNetCore.Builder; @@ -32,6 +32,12 @@ namespace ApplicationA endpoints.MapGet("/", async context => { await context.Response.WriteAsync("Hello from Application A " + Environment.GetEnvironmentVariable("APP_INSTANCE") ?? Environment.GetEnvironmentVariable("HOSTNAME")); + await context.Response.WriteAsync(context.Request.Path); + }); + + endpoints.MapGet("/C/test", async context => + { + await context.Response.WriteAsync("Hit path /C/test"); }); // This method returns the body content and query string back to the caller, to test that the ingress passes those properly diff --git a/test/E2ETest/testassets/projects/apps-with-ingress/tye.yaml b/test/E2ETest/testassets/projects/apps-with-ingress/tye.yaml index b334617b..0cbe073f 100644 --- a/test/E2ETest/testassets/projects/apps-with-ingress/tye.yaml +++ b/test/E2ETest/testassets/projects/apps-with-ingress/tye.yaml @@ -14,6 +14,9 @@ ingress: service: appA - path: /B service: appB + - path: /C + service: appA + preservePath: true - host: a.example.com service: appA - host: b.example.com