mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-04-22 18:22:49 +08:00
* #555 added some tests for this issue but struggling to replicate * #555 removed cmd=instance from service fabric code as someone who knows service fabric says its not needed I * #555 renamed test
This commit is contained in:
parent
b0bdeb9402
commit
369fc5b7a4
@ -117,24 +117,12 @@ namespace Ocelot.DownstreamUrlCreator.Middleware
|
|||||||
{
|
{
|
||||||
var query = context.DownstreamRequest.Query;
|
var query = context.DownstreamRequest.Query;
|
||||||
var serviceFabricPath = $"/{context.DownstreamReRoute.ServiceName + dsPath.Data.Value}";
|
var serviceFabricPath = $"/{context.DownstreamReRoute.ServiceName + dsPath.Data.Value}";
|
||||||
|
|
||||||
if (RequestForStatefullService(query))
|
|
||||||
{
|
|
||||||
return (serviceFabricPath, query);
|
return (serviceFabricPath, query);
|
||||||
}
|
}
|
||||||
|
|
||||||
var split = string.IsNullOrEmpty(query) ? "?" : "&";
|
|
||||||
return (serviceFabricPath, $"{query}{split}cmd=instance");
|
|
||||||
}
|
|
||||||
|
|
||||||
private static bool ServiceFabricRequest(DownstreamContext context)
|
private static bool ServiceFabricRequest(DownstreamContext context)
|
||||||
{
|
{
|
||||||
return context.Configuration.ServiceProviderConfiguration.Type == "ServiceFabric" && context.DownstreamReRoute.UseServiceDiscovery;
|
return context.Configuration.ServiceProviderConfiguration.Type == "ServiceFabric" && context.DownstreamReRoute.UseServiceDiscovery;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool RequestForStatefullService(string query)
|
|
||||||
{
|
|
||||||
return query.Contains("PartitionKind") && query.Contains("PartitionKey");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,43 @@ namespace Ocelot.AcceptanceTests
|
|||||||
_steps = new Steps();
|
_steps = new Steps();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void should_fix_issue_555()
|
||||||
|
{
|
||||||
|
var configuration = new FileConfiguration
|
||||||
|
{
|
||||||
|
ReRoutes = new List<FileReRoute>
|
||||||
|
{
|
||||||
|
new FileReRoute
|
||||||
|
{
|
||||||
|
DownstreamPathTemplate = "/{everything}",
|
||||||
|
DownstreamScheme = "http",
|
||||||
|
UpstreamPathTemplate = "/{everything}",
|
||||||
|
UpstreamHttpMethod = new List<string> { "Get" },
|
||||||
|
UseServiceDiscovery = true,
|
||||||
|
ServiceName = "OcelotServiceApplication/OcelotApplicationService"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
GlobalConfiguration = new FileGlobalConfiguration
|
||||||
|
{
|
||||||
|
ServiceDiscoveryProvider = new FileServiceDiscoveryProvider()
|
||||||
|
{
|
||||||
|
Host = "localhost",
|
||||||
|
Port = 19081,
|
||||||
|
Type = "ServiceFabric"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:19081", "/OcelotServiceApplication/OcelotApplicationService/a", 200, "Hello from Laura", "b=c"))
|
||||||
|
.And(x => _steps.GivenThereIsAConfiguration(configuration))
|
||||||
|
.And(x => _steps.GivenOcelotIsRunning())
|
||||||
|
.When(x => _steps.WhenIGetUrlOnTheApiGateway("/a?b=c"))
|
||||||
|
.Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK))
|
||||||
|
.And(x => _steps.ThenTheResponseBodyShouldBe("Hello from Laura"))
|
||||||
|
.BDDfy();
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void should_support_service_fabric_naming_and_dns_service_stateless_and_guest()
|
public void should_support_service_fabric_naming_and_dns_service_stateless_and_guest()
|
||||||
{
|
{
|
||||||
@ -48,10 +85,10 @@ namespace Ocelot.AcceptanceTests
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:19081", "/OcelotServiceApplication/OcelotApplicationService/api/values", 200, "Hello from Laura", "cmd=instance"))
|
this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:19081", "/OcelotServiceApplication/OcelotApplicationService/api/values", 200, "Hello from Laura", "test=best"))
|
||||||
.And(x => _steps.GivenThereIsAConfiguration(configuration))
|
.And(x => _steps.GivenThereIsAConfiguration(configuration))
|
||||||
.And(x => _steps.GivenOcelotIsRunning())
|
.And(x => _steps.GivenOcelotIsRunning())
|
||||||
.When(x => _steps.WhenIGetUrlOnTheApiGateway("/EquipmentInterfaces"))
|
.When(x => _steps.WhenIGetUrlOnTheApiGateway("/EquipmentInterfaces?test=best"))
|
||||||
.Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK))
|
.Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK))
|
||||||
.And(x => _steps.ThenTheResponseBodyShouldBe("Hello from Laura"))
|
.And(x => _steps.ThenTheResponseBodyShouldBe("Hello from Laura"))
|
||||||
.BDDfy();
|
.BDDfy();
|
||||||
|
@ -225,7 +225,7 @@
|
|||||||
.And(x => x.GivenTheDownstreamRequestUriIs("http://localhost:19081"))
|
.And(x => x.GivenTheDownstreamRequestUriIs("http://localhost:19081"))
|
||||||
.And(x => x.GivenTheUrlReplacerWillReturn("/api/products/1"))
|
.And(x => x.GivenTheUrlReplacerWillReturn("/api/products/1"))
|
||||||
.When(x => x.WhenICallTheMiddleware())
|
.When(x => x.WhenICallTheMiddleware())
|
||||||
.Then(x => x.ThenTheDownstreamRequestUriIs("http://localhost:19081/Ocelot/OcelotApp/api/products/1?cmd=instance"))
|
.Then(x => x.ThenTheDownstreamRequestUriIs("http://localhost:19081/Ocelot/OcelotApp/api/products/1"))
|
||||||
.BDDfy();
|
.BDDfy();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -255,7 +255,7 @@
|
|||||||
.And(x => x.GivenTheDownstreamRequestUriIs("http://localhost:19081?Tom=test&laura=1"))
|
.And(x => x.GivenTheDownstreamRequestUriIs("http://localhost:19081?Tom=test&laura=1"))
|
||||||
.And(x => x.GivenTheUrlReplacerWillReturn("/api/products/1"))
|
.And(x => x.GivenTheUrlReplacerWillReturn("/api/products/1"))
|
||||||
.When(x => x.WhenICallTheMiddleware())
|
.When(x => x.WhenICallTheMiddleware())
|
||||||
.Then(x => x.ThenTheDownstreamRequestUriIs("http://localhost:19081/Ocelot/OcelotApp/api/products/1?Tom=test&laura=1&cmd=instance"))
|
.Then(x => x.ThenTheDownstreamRequestUriIs("http://localhost:19081/Ocelot/OcelotApp/api/products/1?Tom=test&laura=1"))
|
||||||
.BDDfy();
|
.BDDfy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
21
test/Ocelot.UnitTests/Request/DownstreamRequestTests.cs
Normal file
21
test/Ocelot.UnitTests/Request/DownstreamRequestTests.cs
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
using System;
|
||||||
|
using System.Net.Http;
|
||||||
|
using Ocelot.Request.Middleware;
|
||||||
|
using Shouldly;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace Ocelot.UnitTests.Request
|
||||||
|
{
|
||||||
|
public class DownstreamRequestTests
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public void should_have_question_mark_with_question_mark_prefixed()
|
||||||
|
{
|
||||||
|
var httpRequestMessage = new HttpRequestMessage();
|
||||||
|
httpRequestMessage.RequestUri = new Uri("https://example.com/a?b=c");
|
||||||
|
var downstreamRequest = new DownstreamRequest(httpRequestMessage);
|
||||||
|
var result = downstreamRequest.ToHttpRequestMessage();
|
||||||
|
result.RequestUri.Query.ShouldBe("?b=c");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user