Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/fix admin api caching wrong re routes #421

Merged
merged 5 commits into from Jun 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1,028 changes: 514 additions & 514 deletions build.cake

Large diffs are not rendered by default.

Expand Up @@ -252,7 +252,7 @@ private string CreateReRouteKey(FileReRoute fileReRoute)
return $"{nameof(CookieStickySessions)}:{fileReRoute.LoadBalancerOptions.Key}";
}

return $"{fileReRoute.UpstreamPathTemplate}|{string.Join(",", fileReRoute.UpstreamHttpMethod)}";
return $"{fileReRoute.UpstreamPathTemplate}|{string.Join(",", fileReRoute.UpstreamHttpMethod)}|{string.Join(",", fileReRoute.DownstreamHostAndPorts.Select(x => $"{x.Host}:{x.Port}"))}";
}
}
}
22 changes: 11 additions & 11 deletions src/Ocelot/Configuration/Setter/IFileConfigurationSetter.cs
@@ -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);
}
}
110 changes: 55 additions & 55 deletions src/Ocelot/Headers/HttpResponseHeaderReplacer.cs
@@ -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();
}
}
}
@@ -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);
}
}
}