#473 dont remove query string param (#481)

This commit is contained in:
Tom Pallister 2018-07-20 23:10:59 +01:00 committed by GitHub
parent 5e91d30352
commit 7dbfc46e7b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 42 additions and 1 deletions

View File

@ -52,9 +52,17 @@ namespace Ocelot.DownstreamUrlCreator.Middleware
if(ContainsQueryString(dsPath)) if(ContainsQueryString(dsPath))
{ {
context.DownstreamRequest.AbsolutePath = GetPath(dsPath); context.DownstreamRequest.AbsolutePath = GetPath(dsPath);
if (string.IsNullOrEmpty(context.DownstreamRequest.Query))
{
context.DownstreamRequest.Query = GetQueryString(dsPath); context.DownstreamRequest.Query = GetQueryString(dsPath);
} }
else else
{
context.DownstreamRequest.Query += GetQueryString(dsPath).Replace('?', '&');
}
}
else
{ {
RemoveQueryStringParametersThatHaveBeenUsedInTemplate(context); RemoveQueryStringParametersThatHaveBeenUsedInTemplate(context);

View File

@ -289,6 +289,39 @@
.BDDfy(); .BDDfy();
} }
[Fact]
public void issue_473_should_not_remove_additional_query_string()
{
var downstreamReRoute = new DownstreamReRouteBuilder()
.WithDownstreamPathTemplate("/Authorized/{action}?server={server}")
.WithUpstreamHttpMethod(new List<string> { "Post", "Get" })
.WithDownstreamScheme("http")
.WithUpstreamPathTemplate("/uc/Authorized/{server}/{action}")
.Build();
var config = new ServiceProviderConfigurationBuilder()
.Build();
this.Given(x => x.GivenTheDownStreamRouteIs(
new DownstreamRoute(
new List<PlaceholderNameAndValue>
{
new PlaceholderNameAndValue("{action}", "1"),
new PlaceholderNameAndValue("{server}", "2")
},
new ReRouteBuilder()
.WithDownstreamReRoute(downstreamReRoute)
.WithUpstreamHttpMethod(new List<string> { "Post", "Get" })
.Build())))
.And(x => x.GivenTheDownstreamRequestUriIs("http://localhost:5000/uc/Authorized/2/1/refresh?refreshToken=2288356cfb1338fdc5ff4ca558ec785118dfe1ff2864340937da8226863ff66d"))
.And(x => GivenTheServiceProviderConfigIs(config))
.And(x => x.GivenTheUrlReplacerWillReturn("/Authorized/1?server=2"))
.When(x => x.WhenICallTheMiddleware())
.Then(x => x.ThenTheDownstreamRequestUriIs("http://localhost:5000/Authorized/1?refreshToken=2288356cfb1338fdc5ff4ca558ec785118dfe1ff2864340937da8226863ff66d&server=2"))
.And(x => ThenTheQueryStringIs("?refreshToken=2288356cfb1338fdc5ff4ca558ec785118dfe1ff2864340937da8226863ff66d&server=2"))
.BDDfy();
}
private void GivenTheServiceProviderConfigIs(ServiceProviderConfiguration config) private void GivenTheServiceProviderConfigIs(ServiceProviderConfiguration config)
{ {
var configuration = new InternalConfiguration(null, null, config, null, null, null, null, null); var configuration = new InternalConfiguration(null, null, config, null, null, null, null, null);