mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-06-17 22:23:21 +08:00
#330 Fix and issue with the httpclient being cached on the url but not taking the http verb into accont. This caused an issue because if the same url but different verbs had handlers, the incorrect handler would be called (#331)
This commit is contained in:
parent
fad190fcae
commit
027bf6867a
@ -97,7 +97,11 @@ namespace Ocelot.Requester
|
||||
|
||||
private string GetCacheKey(DownstreamContext request)
|
||||
{
|
||||
return request.DownstreamRequest.OriginalString;
|
||||
var cacheKey = $"{request.DownstreamRequest.Method}:{request.DownstreamRequest.OriginalString}";
|
||||
|
||||
this._logger.LogDebug($"Cache key for request is {cacheKey}");
|
||||
|
||||
return cacheKey;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -130,6 +130,38 @@ namespace Ocelot.UnitTests.Requester
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("GET")]
|
||||
[InlineData("POST")]
|
||||
[InlineData("PUT")]
|
||||
[InlineData("DELETE")]
|
||||
[InlineData("PATCH")]
|
||||
public void should_add_verb_to_cache_key(string verb)
|
||||
{
|
||||
var client = "http://localhost:5012";
|
||||
|
||||
HttpMethod method = new HttpMethod(verb);
|
||||
|
||||
var reRoute = new DownstreamReRouteBuilder()
|
||||
.WithIsQos(false)
|
||||
.WithHttpHandlerOptions(new HttpHandlerOptions(false, false, false))
|
||||
.WithReRouteKey("")
|
||||
.WithQosOptions(new QoSOptionsBuilder().Build())
|
||||
.Build();
|
||||
|
||||
this.Given(_ => GivenADownstreamService())
|
||||
.And(_ => GivenARequestWithAUrlAndMethod(reRoute, client, method))
|
||||
.And(_ => GivenTheFactoryReturnsNothing())
|
||||
.And(_ => WhenIBuild())
|
||||
.And(_ => GivenCacheIsCalledWithExpectedKey($"{method.ToString()}:{client}"))
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
private void GivenCacheIsCalledWithExpectedKey(string expectedKey)
|
||||
{
|
||||
this._cacheHandlers.Verify(x => x.Get(It.Is<string>(p => p.Equals(expectedKey, StringComparison.OrdinalIgnoreCase))), Times.Once);
|
||||
}
|
||||
|
||||
private void ThenTheDangerousAcceptAnyServerCertificateValidatorWarningIsLogged()
|
||||
{
|
||||
_logger.Verify(x => x.LogWarning($"You have ignored all SSL warnings by using DangerousAcceptAnyServerCertificateValidator for this DownstreamReRoute, UpstreamPathTemplate: {_context.DownstreamReRoute.UpstreamPathTemplate}, DownstreamPathTemplate: {_context.DownstreamReRoute.DownstreamPathTemplate}"), Times.Once);
|
||||
@ -197,11 +229,16 @@ namespace Ocelot.UnitTests.Requester
|
||||
}
|
||||
|
||||
private void GivenARequest(DownstreamReRoute downstream)
|
||||
{
|
||||
GivenARequestWithAUrlAndMethod(downstream, "http://localhost:5003", HttpMethod.Get);
|
||||
}
|
||||
|
||||
private void GivenARequestWithAUrlAndMethod(DownstreamReRoute downstream, string url, HttpMethod method)
|
||||
{
|
||||
var context = new DownstreamContext(new DefaultHttpContext())
|
||||
{
|
||||
DownstreamReRoute = downstream,
|
||||
DownstreamRequest = new DownstreamRequest(new HttpRequestMessage() { RequestUri = new Uri("http://localhost:5003") }),
|
||||
DownstreamRequest = new DownstreamRequest(new HttpRequestMessage() { RequestUri = new Uri(url), Method = method }),
|
||||
};
|
||||
|
||||
_context = context;
|
||||
|
Loading…
x
Reference in New Issue
Block a user