Browse Source

passing query string in ingress (#507)

pull/520/head
areller 6 years ago
committed by GitHub
parent
commit
deaf0aaf87
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      src/Microsoft.Tye.Hosting/HttpProxyService.cs
  2. 34
      test/E2ETest/TyeRunTests.cs
  3. 19
      test/E2ETest/testassets/projects/apps-with-ingress/ApplicationA/Startup.cs
  4. 19
      test/E2ETest/testassets/projects/apps-with-ingress/ApplicationB/Startup.cs

3
src/Microsoft.Tye.Hosting/HttpProxyService.cs

@ -154,7 +154,8 @@ namespace Microsoft.Tye.Hosting
var uri = new UriBuilder(uris[next].Uri)
{
Path = (string)context.Request.RouteValues["path"]
Path = (string)context.Request.RouteValues["path"],
Query = context.Request.QueryString.Value
};
await context.ProxyRequest(invoker, uri.Uri);

34
test/E2ETest/TyeRunTests.cs

@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.
using System;
using System.Collections.Generic;
using System.CommandLine.IO;
using System.IO;
using System.Linq;
@ -517,6 +518,39 @@ namespace E2ETest
});
}
[Fact]
public async Task IngressQueryAndContentProxyingTest()
{
using var projectDirectory = CopyTestProjectDirectory("apps-with-ingress");
var projectFile = new FileInfo(Path.Combine(projectDirectory.DirectoryPath, "tye.yaml"));
var outputContext = new OutputContext(_sink, Verbosity.Debug);
var application = await ApplicationFactory.CreateAsync(outputContext, projectFile);
var handler = new HttpClientHandler
{
ServerCertificateCustomValidationCallback = (a, b, c, d) => true,
AllowAutoRedirect = false
};
var client = new HttpClient(new RetryHandler(handler));
await RunHostingApplication(application, new HostOptions(), async (app, uri) =>
{
var ingressUri = await GetServiceUrl(client, uri, "ingress");
var request = new HttpRequestMessage(HttpMethod.Post, ingressUri + "/A/data?key1=value1&key2=value2");
request.Content = new StringContent("some content");
var response = await client.SendAsync(request);
var responseContent =
JsonSerializer.Deserialize<Dictionary<string, string>>(await response.Content.ReadAsStringAsync());
Assert.Equal("some content", responseContent["content"]);
Assert.Equal("?key1=value1&key2=value2", responseContent["query"]);
});
}
[ConditionalFact]
[SkipIfDockerNotRunning]
public async Task NginxIngressTest()

19
test/E2ETest/testassets/projects/apps-with-ingress/ApplicationA/Startup.cs

@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.IO;
using System.Text.Json;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
@ -34,6 +33,20 @@ namespace ApplicationA
{
await context.Response.WriteAsync("Hello from Application A " + Environment.GetEnvironmentVariable("APP_INSTANCE") ?? Environment.GetEnvironmentVariable("HOSTNAME"));
});
// This method returns the body content and query string back to the caller, to test that the ingress passes those properly
endpoints.MapPost("/data", async context =>
{
using var reader = new StreamReader(context.Request.Body);
var content = await reader.ReadToEndAsync();
var query = context.Request.QueryString.Value;
await context.Response.WriteAsync(JsonSerializer.Serialize(new
{
content,
query
}));
});
});
}
}

19
test/E2ETest/testassets/projects/apps-with-ingress/ApplicationB/Startup.cs

@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.IO;
using System.Text.Json;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
@ -34,6 +33,20 @@ namespace ApplicationB
{
await context.Response.WriteAsync("Hello from Application B " + Environment.GetEnvironmentVariable("APP_INSTANCE") ?? Environment.GetEnvironmentVariable("HOSTNAME"));
});
// This method returns the body content and query string back to the caller, to test that the ingress passes those properly
endpoints.MapPost("/data", async context =>
{
using var reader = new StreamReader(context.Request.Body);
var content = await reader.ReadToEndAsync();
var query = context.Request.QueryString.Value;
await context.Response.WriteAsync(JsonSerializer.Serialize(new
{
content,
query
}));
});
});
}
}

Loading…
Cancel
Save