Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/fix admin api caching wrong re routes (#421)
* #383 added failing test for this issue * #383 identified issue was with cached load balancer for a given upstream path template based on the key we use, have modified this to include more data, I guess this might be an issue again for other things so I will have a think about it * #383 fixed failing tests after key change * Seems to be an issue with coveralls new package not being on nuget...try same version as their nuget package * bash the old manual tests json back in
- Loading branch information
1 parent
fffc4c8
commit 3eb9b4d
Showing
8 changed files
with
1,903 additions
and
1,731 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 11 additions & 11 deletions
22
src/Ocelot/Configuration/Setter/IFileConfigurationSetter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
using System.Threading.Tasks; | ||
using Ocelot.Configuration.File; | ||
using Ocelot.Responses; | ||
|
||
namespace Ocelot.Configuration.Setter | ||
{ | ||
public interface IFileConfigurationSetter | ||
{ | ||
Task<Response> Set(FileConfiguration config); | ||
} | ||
} | ||
using System.Threading.Tasks; | ||
using Ocelot.Configuration.File; | ||
using Ocelot.Responses; | ||
|
||
namespace Ocelot.Configuration.Setter | ||
{ | ||
public interface IFileConfigurationSetter | ||
{ | ||
Task<Response> Set(FileConfiguration config); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,55 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Ocelot.Configuration; | ||
using Ocelot.Infrastructure; | ||
using Ocelot.Infrastructure.Extensions; | ||
using Ocelot.Middleware; | ||
using Ocelot.Middleware.Multiplexer; | ||
using Ocelot.Request.Middleware; | ||
using Ocelot.Responses; | ||
|
||
namespace Ocelot.Headers | ||
{ | ||
public class HttpResponseHeaderReplacer : IHttpResponseHeaderReplacer | ||
{ | ||
private readonly IPlaceholders _placeholders; | ||
|
||
public HttpResponseHeaderReplacer(IPlaceholders placeholders) | ||
{ | ||
_placeholders = placeholders; | ||
} | ||
|
||
public Response Replace(DownstreamResponse response, List<HeaderFindAndReplace> fAndRs, DownstreamRequest request) | ||
{ | ||
foreach (var f in fAndRs) | ||
{ | ||
var dict = response.Headers.ToDictionary(x => x.Key); | ||
|
||
//if the response headers contain a matching find and replace | ||
if(dict.TryGetValue(f.Key, out var values)) | ||
{ | ||
//check to see if it is a placeholder in the find... | ||
var placeholderValue = _placeholders.Get(f.Find, request); | ||
|
||
if(!placeholderValue.IsError) | ||
{ | ||
//if it is we need to get the value of the placeholder | ||
var replaced = values.Values.ToList()[f.Index].Replace(placeholderValue.Data, f.Replace.LastCharAsForwardSlash()); | ||
|
||
response.Headers.Remove(response.Headers.First(item => item.Key == f.Key)); | ||
response.Headers.Add(new Header(f.Key, new List<string> { replaced })); | ||
} | ||
else | ||
{ | ||
var replaced = values.Values.ToList()[f.Index].Replace(f.Find, f.Replace); | ||
|
||
response.Headers.Remove(response.Headers.First(item => item.Key == f.Key)); | ||
response.Headers.Add(new Header(f.Key, new List<string> { replaced })); | ||
} | ||
} | ||
} | ||
|
||
return new OkResponse(); | ||
} | ||
} | ||
} | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Ocelot.Configuration; | ||
using Ocelot.Infrastructure; | ||
using Ocelot.Infrastructure.Extensions; | ||
using Ocelot.Middleware; | ||
using Ocelot.Middleware.Multiplexer; | ||
using Ocelot.Request.Middleware; | ||
using Ocelot.Responses; | ||
|
||
namespace Ocelot.Headers | ||
{ | ||
public class HttpResponseHeaderReplacer : IHttpResponseHeaderReplacer | ||
{ | ||
private readonly IPlaceholders _placeholders; | ||
|
||
public HttpResponseHeaderReplacer(IPlaceholders placeholders) | ||
{ | ||
_placeholders = placeholders; | ||
} | ||
|
||
public Response Replace(DownstreamResponse response, List<HeaderFindAndReplace> fAndRs, DownstreamRequest request) | ||
{ | ||
foreach (var f in fAndRs) | ||
{ | ||
var dict = response.Headers.ToDictionary(x => x.Key); | ||
|
||
//if the response headers contain a matching find and replace | ||
if(dict.TryGetValue(f.Key, out var values)) | ||
{ | ||
//check to see if it is a placeholder in the find... | ||
var placeholderValue = _placeholders.Get(f.Find, request); | ||
|
||
if(!placeholderValue.IsError) | ||
{ | ||
//if it is we need to get the value of the placeholder | ||
var replaced = values.Values.ToList()[f.Index].Replace(placeholderValue.Data, f.Replace.LastCharAsForwardSlash()); | ||
|
||
response.Headers.Remove(response.Headers.First(item => item.Key == f.Key)); | ||
response.Headers.Add(new Header(f.Key, new List<string> { replaced })); | ||
} | ||
else | ||
{ | ||
var replaced = values.Values.ToList()[f.Index].Replace(f.Find, f.Replace); | ||
|
||
response.Headers.Remove(response.Headers.First(item => item.Key == f.Key)); | ||
response.Headers.Add(new Header(f.Key, new List<string> { replaced })); | ||
} | ||
} | ||
} | ||
|
||
return new OkResponse(); | ||
} | ||
} | ||
} |
96 changes: 48 additions & 48 deletions
96
src/Ocelot/Headers/Middleware/HttpHeadersTransformationMiddleware.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,48 @@ | ||
using System.Threading.Tasks; | ||
using Ocelot.Logging; | ||
using Ocelot.Middleware; | ||
|
||
namespace Ocelot.Headers.Middleware | ||
{ | ||
public class HttpHeadersTransformationMiddleware : OcelotMiddleware | ||
{ | ||
private readonly OcelotRequestDelegate _next; | ||
private readonly IHttpContextRequestHeaderReplacer _preReplacer; | ||
private readonly IHttpResponseHeaderReplacer _postReplacer; | ||
private readonly IAddHeadersToResponse _addHeadersToResponse; | ||
private readonly IAddHeadersToRequest _addHeadersToRequest; | ||
|
||
public HttpHeadersTransformationMiddleware(OcelotRequestDelegate next, | ||
IOcelotLoggerFactory loggerFactory, | ||
IHttpContextRequestHeaderReplacer preReplacer, | ||
IHttpResponseHeaderReplacer postReplacer, | ||
IAddHeadersToResponse addHeadersToResponse, | ||
IAddHeadersToRequest addHeadersToRequest) | ||
:base(loggerFactory.CreateLogger<HttpHeadersTransformationMiddleware>()) | ||
{ | ||
_addHeadersToResponse = addHeadersToResponse; | ||
_addHeadersToRequest = addHeadersToRequest; | ||
_next = next; | ||
_postReplacer = postReplacer; | ||
_preReplacer = preReplacer; | ||
} | ||
|
||
public async Task Invoke(DownstreamContext context) | ||
{ | ||
var preFAndRs = context.DownstreamReRoute.UpstreamHeadersFindAndReplace; | ||
|
||
//todo - this should be on httprequestmessage not httpcontext? | ||
_preReplacer.Replace(context.HttpContext, preFAndRs); | ||
|
||
_addHeadersToRequest.SetHeadersOnDownstreamRequest(context.DownstreamReRoute.AddHeadersToUpstream, context.HttpContext); | ||
|
||
await _next.Invoke(context); | ||
|
||
var postFAndRs = context.DownstreamReRoute.DownstreamHeadersFindAndReplace; | ||
|
||
_postReplacer.Replace(context.DownstreamResponse, postFAndRs, context.DownstreamRequest); | ||
|
||
_addHeadersToResponse.Add(context.DownstreamReRoute.AddHeadersToDownstream, context.DownstreamResponse); | ||
} | ||
} | ||
} | ||
using System.Threading.Tasks; | ||
using Ocelot.Logging; | ||
using Ocelot.Middleware; | ||
|
||
namespace Ocelot.Headers.Middleware | ||
{ | ||
public class HttpHeadersTransformationMiddleware : OcelotMiddleware | ||
{ | ||
private readonly OcelotRequestDelegate _next; | ||
private readonly IHttpContextRequestHeaderReplacer _preReplacer; | ||
private readonly IHttpResponseHeaderReplacer _postReplacer; | ||
private readonly IAddHeadersToResponse _addHeadersToResponse; | ||
private readonly IAddHeadersToRequest _addHeadersToRequest; | ||
|
||
public HttpHeadersTransformationMiddleware(OcelotRequestDelegate next, | ||
IOcelotLoggerFactory loggerFactory, | ||
IHttpContextRequestHeaderReplacer preReplacer, | ||
IHttpResponseHeaderReplacer postReplacer, | ||
IAddHeadersToResponse addHeadersToResponse, | ||
IAddHeadersToRequest addHeadersToRequest) | ||
:base(loggerFactory.CreateLogger<HttpHeadersTransformationMiddleware>()) | ||
{ | ||
_addHeadersToResponse = addHeadersToResponse; | ||
_addHeadersToRequest = addHeadersToRequest; | ||
_next = next; | ||
_postReplacer = postReplacer; | ||
_preReplacer = preReplacer; | ||
} | ||
|
||
public async Task Invoke(DownstreamContext context) | ||
{ | ||
var preFAndRs = context.DownstreamReRoute.UpstreamHeadersFindAndReplace; | ||
|
||
//todo - this should be on httprequestmessage not httpcontext? | ||
_preReplacer.Replace(context.HttpContext, preFAndRs); | ||
|
||
_addHeadersToRequest.SetHeadersOnDownstreamRequest(context.DownstreamReRoute.AddHeadersToUpstream, context.HttpContext); | ||
|
||
await _next.Invoke(context); | ||
|
||
var postFAndRs = context.DownstreamReRoute.DownstreamHeadersFindAndReplace; | ||
|
||
_postReplacer.Replace(context.DownstreamResponse, postFAndRs, context.DownstreamRequest); | ||
|
||
_addHeadersToResponse.Add(context.DownstreamReRoute.AddHeadersToDownstream, context.DownstreamResponse); | ||
} | ||
} | ||
} |
Oops, something went wrong.