mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-04-22 14:02:49 +08:00
added benchmarks back in, renamed data repository and a few other things
This commit is contained in:
parent
d50f06fc3e
commit
9c771bf9e0
@ -6,31 +6,33 @@ using Ocelot.Authentication.Handler.Factory;
|
||||
using Ocelot.Configuration;
|
||||
using Ocelot.DownstreamRouteFinder;
|
||||
using Ocelot.Errors;
|
||||
using Ocelot.Infrastructure.RequestData;
|
||||
using Ocelot.Middleware;
|
||||
using Ocelot.ScopedData;
|
||||
|
||||
namespace Ocelot.Authentication.Middleware
|
||||
{
|
||||
public class AuthenticationMiddleware : OcelotMiddleware
|
||||
{
|
||||
private readonly RequestDelegate _next;
|
||||
private readonly IScopedRequestDataRepository _scopedRequestDataRepository;
|
||||
private readonly IRequestScopedDataRepository _requestScopedDataRepository;
|
||||
private readonly IApplicationBuilder _app;
|
||||
private readonly IAuthenticationHandlerFactory _authHandlerFactory;
|
||||
|
||||
public AuthenticationMiddleware(RequestDelegate next, IApplicationBuilder app,
|
||||
IScopedRequestDataRepository scopedRequestDataRepository, IAuthenticationHandlerFactory authHandlerFactory)
|
||||
: base(scopedRequestDataRepository)
|
||||
public AuthenticationMiddleware(RequestDelegate next,
|
||||
IApplicationBuilder app,
|
||||
IRequestScopedDataRepository requestScopedDataRepository,
|
||||
IAuthenticationHandlerFactory authHandlerFactory)
|
||||
: base(requestScopedDataRepository)
|
||||
{
|
||||
_next = next;
|
||||
_scopedRequestDataRepository = scopedRequestDataRepository;
|
||||
_requestScopedDataRepository = requestScopedDataRepository;
|
||||
_authHandlerFactory = authHandlerFactory;
|
||||
_app = app;
|
||||
}
|
||||
|
||||
public async Task Invoke(HttpContext context)
|
||||
{
|
||||
var downstreamRoute = _scopedRequestDataRepository.Get<DownstreamRoute>("DownstreamRoute");
|
||||
var downstreamRoute = _requestScopedDataRepository.Get<DownstreamRoute>("DownstreamRoute");
|
||||
|
||||
if (downstreamRoute.IsError)
|
||||
{
|
||||
|
@ -1,4 +1,6 @@
|
||||
namespace Ocelot.Authorisation.Middleware
|
||||
using Ocelot.Infrastructure.RequestData;
|
||||
|
||||
namespace Ocelot.Authorisation.Middleware
|
||||
{
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
@ -6,27 +8,26 @@
|
||||
using Errors;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Ocelot.Middleware;
|
||||
using ScopedData;
|
||||
|
||||
public class AuthorisationMiddleware : OcelotMiddleware
|
||||
{
|
||||
private readonly RequestDelegate _next;
|
||||
private readonly IScopedRequestDataRepository _scopedRequestDataRepository;
|
||||
private readonly IRequestScopedDataRepository _requestScopedDataRepository;
|
||||
private readonly IAuthoriser _authoriser;
|
||||
|
||||
public AuthorisationMiddleware(RequestDelegate next,
|
||||
IScopedRequestDataRepository scopedRequestDataRepository,
|
||||
IRequestScopedDataRepository requestScopedDataRepository,
|
||||
IAuthoriser authoriser)
|
||||
: base(scopedRequestDataRepository)
|
||||
: base(requestScopedDataRepository)
|
||||
{
|
||||
_next = next;
|
||||
_scopedRequestDataRepository = scopedRequestDataRepository;
|
||||
_requestScopedDataRepository = requestScopedDataRepository;
|
||||
_authoriser = authoriser;
|
||||
}
|
||||
|
||||
public async Task Invoke(HttpContext context)
|
||||
{
|
||||
var downstreamRoute = _scopedRequestDataRepository.Get<DownstreamRoute>("DownstreamRoute");
|
||||
var downstreamRoute = _requestScopedDataRepository.Get<DownstreamRoute>("DownstreamRoute");
|
||||
|
||||
if (downstreamRoute.IsError)
|
||||
{
|
||||
|
@ -1,31 +1,32 @@
|
||||
namespace Ocelot.ClaimsBuilder.Middleware
|
||||
using Ocelot.Infrastructure.RequestData;
|
||||
|
||||
namespace Ocelot.ClaimsBuilder.Middleware
|
||||
{
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using DownstreamRouteFinder;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Ocelot.Middleware;
|
||||
using ScopedData;
|
||||
|
||||
public class ClaimsBuilderMiddleware : OcelotMiddleware
|
||||
{
|
||||
private readonly RequestDelegate _next;
|
||||
private readonly IAddClaimsToRequest _addClaimsToRequest;
|
||||
private readonly IScopedRequestDataRepository _scopedRequestDataRepository;
|
||||
private readonly IRequestScopedDataRepository _requestScopedDataRepository;
|
||||
|
||||
public ClaimsBuilderMiddleware(RequestDelegate next,
|
||||
IScopedRequestDataRepository scopedRequestDataRepository,
|
||||
IRequestScopedDataRepository requestScopedDataRepository,
|
||||
IAddClaimsToRequest addClaimsToRequest)
|
||||
: base(scopedRequestDataRepository)
|
||||
: base(requestScopedDataRepository)
|
||||
{
|
||||
_next = next;
|
||||
_addClaimsToRequest = addClaimsToRequest;
|
||||
_scopedRequestDataRepository = scopedRequestDataRepository;
|
||||
_requestScopedDataRepository = requestScopedDataRepository;
|
||||
}
|
||||
|
||||
public async Task Invoke(HttpContext context)
|
||||
{
|
||||
var downstreamRoute = _scopedRequestDataRepository.Get<DownstreamRoute>("DownstreamRoute");
|
||||
var downstreamRoute = _requestScopedDataRepository.Get<DownstreamRoute>("DownstreamRoute");
|
||||
|
||||
if (downstreamRoute.Data.ReRoute.ClaimsToClaims.Any())
|
||||
{
|
||||
|
@ -65,20 +65,19 @@ namespace Ocelot.Configuration.Validator
|
||||
|
||||
private ConfigurationValidationResult CheckForDupliateReRoutes(YamlConfiguration configuration)
|
||||
{
|
||||
var duplicateUpstreamTemplates = configuration.ReRoutes
|
||||
.Select(r => r.DownstreamTemplate)
|
||||
.GroupBy(r => r)
|
||||
.Where(r => r.Count() > 1)
|
||||
.Select(r => r.Key)
|
||||
.ToList();
|
||||
var hasDupes = configuration.ReRoutes
|
||||
.GroupBy(x => new { x.UpstreamTemplate, x.UpstreamHttpMethod }).Any(x => x.Skip(1).Any());
|
||||
|
||||
if (duplicateUpstreamTemplates.Count <= 0)
|
||||
if (!hasDupes)
|
||||
{
|
||||
return new ConfigurationValidationResult(false);
|
||||
}
|
||||
|
||||
var errors = duplicateUpstreamTemplates
|
||||
.Select(duplicateUpstreamTemplate => new DownstreamTemplateAlreadyUsedError(string.Format("Duplicate DownstreamTemplate: {0}", duplicateUpstreamTemplate)))
|
||||
var dupes = configuration.ReRoutes.GroupBy(x => new { x.UpstreamTemplate, x.UpstreamHttpMethod })
|
||||
.Where(x => x.Skip(1).Any());
|
||||
|
||||
var errors = dupes
|
||||
.Select(d => new DownstreamTemplateAlreadyUsedError(string.Format("Duplicate DownstreamTemplate: {0}", d.Key.UpstreamTemplate)))
|
||||
.Cast<Error>()
|
||||
.ToList();
|
||||
|
||||
|
@ -15,10 +15,10 @@ using Ocelot.DownstreamRouteFinder.Finder;
|
||||
using Ocelot.DownstreamRouteFinder.UrlMatcher;
|
||||
using Ocelot.DownstreamUrlCreator.UrlTemplateReplacer;
|
||||
using Ocelot.HeaderBuilder;
|
||||
using Ocelot.Infrastructure.RequestData;
|
||||
using Ocelot.RequestBuilder.Builder;
|
||||
using Ocelot.Requester;
|
||||
using Ocelot.Responder;
|
||||
using Ocelot.ScopedData;
|
||||
|
||||
namespace Ocelot.DependencyInjection
|
||||
{
|
||||
@ -44,7 +44,7 @@ namespace Ocelot.DependencyInjection
|
||||
|
||||
public static IServiceCollection AddOcelot(this IServiceCollection services)
|
||||
{
|
||||
// framework services
|
||||
// framework services dependency for the identity server middleware
|
||||
services.AddMvcCore().AddJsonFormatters();
|
||||
services.AddLogging();
|
||||
|
||||
@ -67,7 +67,7 @@ namespace Ocelot.DependencyInjection
|
||||
// see this for why we register this as singleton http://stackoverflow.com/questions/37371264/invalidoperationexception-unable-to-resolve-service-for-type-microsoft-aspnetc
|
||||
// could maybe use a scoped data repository
|
||||
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
|
||||
services.AddScoped<IScopedRequestDataRepository, ScopedRequestDataRepository>();
|
||||
services.AddScoped<IRequestScopedDataRepository, HttpDataRepository>();
|
||||
|
||||
return services;
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Ocelot.DownstreamRouteFinder.Finder;
|
||||
using Ocelot.Infrastructure.RequestData;
|
||||
using Ocelot.Middleware;
|
||||
using Ocelot.ScopedData;
|
||||
|
||||
namespace Ocelot.DownstreamRouteFinder.Middleware
|
||||
{
|
||||
@ -10,16 +10,16 @@ namespace Ocelot.DownstreamRouteFinder.Middleware
|
||||
{
|
||||
private readonly RequestDelegate _next;
|
||||
private readonly IDownstreamRouteFinder _downstreamRouteFinder;
|
||||
private readonly IScopedRequestDataRepository _scopedRequestDataRepository;
|
||||
private readonly IRequestScopedDataRepository _requestScopedDataRepository;
|
||||
|
||||
public DownstreamRouteFinderMiddleware(RequestDelegate next,
|
||||
IDownstreamRouteFinder downstreamRouteFinder,
|
||||
IScopedRequestDataRepository scopedRequestDataRepository)
|
||||
:base(scopedRequestDataRepository)
|
||||
IRequestScopedDataRepository requestScopedDataRepository)
|
||||
:base(requestScopedDataRepository)
|
||||
{
|
||||
_next = next;
|
||||
_downstreamRouteFinder = downstreamRouteFinder;
|
||||
_scopedRequestDataRepository = scopedRequestDataRepository;
|
||||
_requestScopedDataRepository = requestScopedDataRepository;
|
||||
}
|
||||
|
||||
public async Task Invoke(HttpContext context)
|
||||
@ -34,7 +34,7 @@ namespace Ocelot.DownstreamRouteFinder.Middleware
|
||||
return;
|
||||
}
|
||||
|
||||
_scopedRequestDataRepository.Add("DownstreamRoute", downstreamRoute.Data);
|
||||
_requestScopedDataRepository.Add("DownstreamRoute", downstreamRoute.Data);
|
||||
|
||||
await _next.Invoke(context);
|
||||
}
|
||||
|
@ -2,8 +2,8 @@ using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Ocelot.DownstreamRouteFinder;
|
||||
using Ocelot.DownstreamUrlCreator.UrlTemplateReplacer;
|
||||
using Ocelot.Infrastructure.RequestData;
|
||||
using Ocelot.Middleware;
|
||||
using Ocelot.ScopedData;
|
||||
|
||||
namespace Ocelot.DownstreamUrlCreator.Middleware
|
||||
{
|
||||
@ -11,21 +11,21 @@ namespace Ocelot.DownstreamUrlCreator.Middleware
|
||||
{
|
||||
private readonly RequestDelegate _next;
|
||||
private readonly IDownstreamUrlTemplateVariableReplacer _urlReplacer;
|
||||
private readonly IScopedRequestDataRepository _scopedRequestDataRepository;
|
||||
private readonly IRequestScopedDataRepository _requestScopedDataRepository;
|
||||
|
||||
public DownstreamUrlCreatorMiddleware(RequestDelegate next,
|
||||
IDownstreamUrlTemplateVariableReplacer urlReplacer,
|
||||
IScopedRequestDataRepository scopedRequestDataRepository)
|
||||
:base(scopedRequestDataRepository)
|
||||
IRequestScopedDataRepository requestScopedDataRepository)
|
||||
:base(requestScopedDataRepository)
|
||||
{
|
||||
_next = next;
|
||||
_urlReplacer = urlReplacer;
|
||||
_scopedRequestDataRepository = scopedRequestDataRepository;
|
||||
_requestScopedDataRepository = requestScopedDataRepository;
|
||||
}
|
||||
|
||||
public async Task Invoke(HttpContext context)
|
||||
{
|
||||
var downstreamRoute = _scopedRequestDataRepository.Get<DownstreamRoute>("DownstreamRoute");
|
||||
var downstreamRoute = _requestScopedDataRepository.Get<DownstreamRoute>("DownstreamRoute");
|
||||
|
||||
if (downstreamRoute.IsError)
|
||||
{
|
||||
@ -41,7 +41,7 @@ namespace Ocelot.DownstreamUrlCreator.Middleware
|
||||
return;
|
||||
}
|
||||
|
||||
_scopedRequestDataRepository.Add("DownstreamUrl", downstreamUrl.Data);
|
||||
_requestScopedDataRepository.Add("DownstreamUrl", downstreamUrl.Data);
|
||||
|
||||
await _next.Invoke(context);
|
||||
}
|
||||
|
@ -2,8 +2,8 @@
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Ocelot.DownstreamRouteFinder;
|
||||
using Ocelot.Infrastructure.RequestData;
|
||||
using Ocelot.Middleware;
|
||||
using Ocelot.ScopedData;
|
||||
|
||||
namespace Ocelot.HeaderBuilder.Middleware
|
||||
{
|
||||
@ -11,21 +11,21 @@ namespace Ocelot.HeaderBuilder.Middleware
|
||||
{
|
||||
private readonly RequestDelegate _next;
|
||||
private readonly IAddHeadersToRequest _addHeadersToRequest;
|
||||
private readonly IScopedRequestDataRepository _scopedRequestDataRepository;
|
||||
private readonly IRequestScopedDataRepository _requestScopedDataRepository;
|
||||
|
||||
public HttpRequestHeadersBuilderMiddleware(RequestDelegate next,
|
||||
IScopedRequestDataRepository scopedRequestDataRepository,
|
||||
IRequestScopedDataRepository requestScopedDataRepository,
|
||||
IAddHeadersToRequest addHeadersToRequest)
|
||||
: base(scopedRequestDataRepository)
|
||||
: base(requestScopedDataRepository)
|
||||
{
|
||||
_next = next;
|
||||
_addHeadersToRequest = addHeadersToRequest;
|
||||
_scopedRequestDataRepository = scopedRequestDataRepository;
|
||||
_requestScopedDataRepository = requestScopedDataRepository;
|
||||
}
|
||||
|
||||
public async Task Invoke(HttpContext context)
|
||||
{
|
||||
var downstreamRoute = _scopedRequestDataRepository.Get<DownstreamRoute>("DownstreamRoute");
|
||||
var downstreamRoute = _requestScopedDataRepository.Get<DownstreamRoute>("DownstreamRoute");
|
||||
|
||||
if (downstreamRoute.Data.ReRoute.ClaimsToHeaders.Any())
|
||||
{
|
||||
|
@ -1,6 +1,6 @@
|
||||
using Ocelot.Errors;
|
||||
|
||||
namespace Ocelot.ScopedData
|
||||
namespace Ocelot.Infrastructure.RequestData
|
||||
{
|
||||
public class CannotAddDataError : Error
|
||||
{
|
@ -1,6 +1,6 @@
|
||||
using Ocelot.Errors;
|
||||
|
||||
namespace Ocelot.ScopedData
|
||||
namespace Ocelot.Infrastructure.RequestData
|
||||
{
|
||||
public class CannotFindDataError : Error
|
||||
{
|
@ -4,13 +4,13 @@ using Microsoft.AspNetCore.Http;
|
||||
using Ocelot.Errors;
|
||||
using Ocelot.Responses;
|
||||
|
||||
namespace Ocelot.ScopedData
|
||||
namespace Ocelot.Infrastructure.RequestData
|
||||
{
|
||||
public class ScopedRequestDataRepository : IScopedRequestDataRepository
|
||||
public class HttpDataRepository : IRequestScopedDataRepository
|
||||
{
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
|
||||
public ScopedRequestDataRepository(IHttpContextAccessor httpContextAccessor)
|
||||
public HttpDataRepository(IHttpContextAccessor httpContextAccessor)
|
||||
{
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
}
|
@ -1,8 +1,8 @@
|
||||
using Ocelot.Responses;
|
||||
|
||||
namespace Ocelot.ScopedData
|
||||
namespace Ocelot.Infrastructure.RequestData
|
||||
{
|
||||
public interface IScopedRequestDataRepository
|
||||
public interface IRequestScopedDataRepository
|
||||
{
|
||||
Response Add<T>(string key, T value);
|
||||
Response<T> Get<T>(string key);
|
@ -1,33 +1,33 @@
|
||||
using System.Collections.Generic;
|
||||
using Ocelot.Errors;
|
||||
using Ocelot.ScopedData;
|
||||
using Ocelot.Infrastructure.RequestData;
|
||||
|
||||
namespace Ocelot.Middleware
|
||||
{
|
||||
public abstract class OcelotMiddleware
|
||||
{
|
||||
private readonly IScopedRequestDataRepository _scopedRequestDataRepository;
|
||||
private readonly IRequestScopedDataRepository _requestScopedDataRepository;
|
||||
|
||||
protected OcelotMiddleware(IScopedRequestDataRepository scopedRequestDataRepository)
|
||||
protected OcelotMiddleware(IRequestScopedDataRepository requestScopedDataRepository)
|
||||
{
|
||||
_scopedRequestDataRepository = scopedRequestDataRepository;
|
||||
_requestScopedDataRepository = requestScopedDataRepository;
|
||||
}
|
||||
|
||||
public void SetPipelineError(List<Error> errors)
|
||||
{
|
||||
_scopedRequestDataRepository.Add("OcelotMiddlewareError", true);
|
||||
_scopedRequestDataRepository.Add("OcelotMiddlewareErrors", errors);
|
||||
_requestScopedDataRepository.Add("OcelotMiddlewareError", true);
|
||||
_requestScopedDataRepository.Add("OcelotMiddlewareErrors", errors);
|
||||
}
|
||||
|
||||
public bool PipelineError()
|
||||
{
|
||||
var response = _scopedRequestDataRepository.Get<bool>("OcelotMiddlewareError");
|
||||
var response = _requestScopedDataRepository.Get<bool>("OcelotMiddlewareError");
|
||||
return response.Data;
|
||||
}
|
||||
|
||||
public List<Error> GetPipelineErrors()
|
||||
{
|
||||
var response = _scopedRequestDataRepository.Get<List<Error>>("OcelotMiddlewareErrors");
|
||||
var response = _requestScopedDataRepository.Get<List<Error>>("OcelotMiddlewareErrors");
|
||||
return response.Data;
|
||||
}
|
||||
}
|
||||
|
@ -1,30 +1,30 @@
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Ocelot.Infrastructure.RequestData;
|
||||
using Ocelot.Middleware;
|
||||
using Ocelot.RequestBuilder.Builder;
|
||||
using Ocelot.ScopedData;
|
||||
|
||||
namespace Ocelot.RequestBuilder.Middleware
|
||||
{
|
||||
public class HttpRequestBuilderMiddleware : OcelotMiddleware
|
||||
{
|
||||
private readonly RequestDelegate _next;
|
||||
private readonly IScopedRequestDataRepository _scopedRequestDataRepository;
|
||||
private readonly IRequestScopedDataRepository _requestScopedDataRepository;
|
||||
private readonly IRequestBuilder _requestBuilder;
|
||||
|
||||
public HttpRequestBuilderMiddleware(RequestDelegate next,
|
||||
IScopedRequestDataRepository scopedRequestDataRepository,
|
||||
IRequestScopedDataRepository requestScopedDataRepository,
|
||||
IRequestBuilder requestBuilder)
|
||||
:base(scopedRequestDataRepository)
|
||||
:base(requestScopedDataRepository)
|
||||
{
|
||||
_next = next;
|
||||
_scopedRequestDataRepository = scopedRequestDataRepository;
|
||||
_requestScopedDataRepository = requestScopedDataRepository;
|
||||
_requestBuilder = requestBuilder;
|
||||
}
|
||||
|
||||
public async Task Invoke(HttpContext context)
|
||||
{
|
||||
var downstreamUrl = _scopedRequestDataRepository.Get<string>("DownstreamUrl");
|
||||
var downstreamUrl = _requestScopedDataRepository.Get<string>("DownstreamUrl");
|
||||
|
||||
if (downstreamUrl.IsError)
|
||||
{
|
||||
@ -42,7 +42,7 @@ namespace Ocelot.RequestBuilder.Middleware
|
||||
return;
|
||||
}
|
||||
|
||||
_scopedRequestDataRepository.Add("Request", request.Data);
|
||||
_requestScopedDataRepository.Add("Request", request.Data);
|
||||
|
||||
await _next.Invoke(context);
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Ocelot.Infrastructure.RequestData;
|
||||
using Ocelot.Middleware;
|
||||
using Ocelot.RequestBuilder;
|
||||
using Ocelot.ScopedData;
|
||||
|
||||
namespace Ocelot.Requester.Middleware
|
||||
{
|
||||
@ -10,21 +10,21 @@ namespace Ocelot.Requester.Middleware
|
||||
{
|
||||
private readonly RequestDelegate _next;
|
||||
private readonly IHttpRequester _requester;
|
||||
private readonly IScopedRequestDataRepository _scopedRequestDataRepository;
|
||||
private readonly IRequestScopedDataRepository _requestScopedDataRepository;
|
||||
|
||||
public HttpRequesterMiddleware(RequestDelegate next,
|
||||
IHttpRequester requester,
|
||||
IScopedRequestDataRepository scopedRequestDataRepository)
|
||||
:base(scopedRequestDataRepository)
|
||||
IRequestScopedDataRepository requestScopedDataRepository)
|
||||
:base(requestScopedDataRepository)
|
||||
{
|
||||
_next = next;
|
||||
_requester = requester;
|
||||
_scopedRequestDataRepository = scopedRequestDataRepository;
|
||||
_requestScopedDataRepository = requestScopedDataRepository;
|
||||
}
|
||||
|
||||
public async Task Invoke(HttpContext context)
|
||||
{
|
||||
var request = _scopedRequestDataRepository.Get<Request>("Request");
|
||||
var request = _requestScopedDataRepository.Get<Request>("Request");
|
||||
|
||||
if (request.IsError)
|
||||
{
|
||||
@ -40,7 +40,7 @@ namespace Ocelot.Requester.Middleware
|
||||
return;
|
||||
}
|
||||
|
||||
_scopedRequestDataRepository.Add("Response", response.Data);
|
||||
_requestScopedDataRepository.Add("Response", response.Data);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,8 +1,8 @@
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Ocelot.Infrastructure.RequestData;
|
||||
using Ocelot.Middleware;
|
||||
using Ocelot.ScopedData;
|
||||
|
||||
namespace Ocelot.Responder.Middleware
|
||||
{
|
||||
@ -10,18 +10,18 @@ namespace Ocelot.Responder.Middleware
|
||||
{
|
||||
private readonly RequestDelegate _next;
|
||||
private readonly IHttpResponder _responder;
|
||||
private readonly IScopedRequestDataRepository _scopedRequestDataRepository;
|
||||
private readonly IRequestScopedDataRepository _requestScopedDataRepository;
|
||||
private readonly IErrorsToHttpStatusCodeMapper _codeMapper;
|
||||
|
||||
public HttpResponderMiddleware(RequestDelegate next,
|
||||
IHttpResponder responder,
|
||||
IScopedRequestDataRepository scopedRequestDataRepository,
|
||||
IRequestScopedDataRepository requestScopedDataRepository,
|
||||
IErrorsToHttpStatusCodeMapper codeMapper)
|
||||
:base(scopedRequestDataRepository)
|
||||
:base(requestScopedDataRepository)
|
||||
{
|
||||
_next = next;
|
||||
_responder = responder;
|
||||
_scopedRequestDataRepository = scopedRequestDataRepository;
|
||||
_requestScopedDataRepository = requestScopedDataRepository;
|
||||
_codeMapper = codeMapper;
|
||||
}
|
||||
|
||||
@ -46,7 +46,7 @@ namespace Ocelot.Responder.Middleware
|
||||
}
|
||||
else
|
||||
{
|
||||
var response = _scopedRequestDataRepository.Get<HttpResponseMessage>("Response");
|
||||
var response = _requestScopedDataRepository.Get<HttpResponseMessage>("Response");
|
||||
|
||||
await _responder.CreateResponse(context, response.Data);
|
||||
}
|
||||
|
@ -8,8 +8,8 @@ using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Ocelot.Configuration.Yaml;
|
||||
using Ocelot.Infrastructure.RequestData;
|
||||
using Ocelot.Middleware;
|
||||
using Ocelot.ScopedData;
|
||||
using TestStack.BDDfy;
|
||||
using Xunit;
|
||||
|
||||
@ -67,7 +67,7 @@ namespace Ocelot.AcceptanceTests
|
||||
{
|
||||
PreHttpRequesterMiddleware = async (ctx, next) =>
|
||||
{
|
||||
var service = ctx.RequestServices.GetService<IScopedRequestDataRepository>();
|
||||
var service = ctx.RequestServices.GetService<IRequestScopedDataRepository>();
|
||||
service.Add("Response", new HttpResponseMessage {Content = new StringContent("PreHttpRequesterMiddleware")});
|
||||
}
|
||||
};
|
||||
|
@ -1,4 +1,26 @@
|
||||
ReRoutes:
|
||||
# the url we are forwarding the request to
|
||||
- DownstreamTemplate: http://localhost:52876/
|
||||
# the path we are listening on for this re route
|
||||
UpstreamTemplate: /identityserverexample
|
||||
# the method we are listening for on this re route
|
||||
UpstreamHttpMethod: Get
|
||||
# only support identity server at the moment
|
||||
AuthenticationOptions:
|
||||
Provider: IdentityServer
|
||||
ProviderRootUrl: http://localhost:52888
|
||||
ScopeName: api
|
||||
AdditionalScopes:
|
||||
- openid
|
||||
- offline_access
|
||||
#require if using reference tokens
|
||||
ScopeSecret: secret
|
||||
# WARNING - will overwrite any headers already in the request with these values
|
||||
AddHeadersToRequest:
|
||||
CustomerId: Claims[CustomerId] > value
|
||||
LocationId: Claims[LocationId] > value
|
||||
UserType: Claims[sub] > value[0] > |
|
||||
UserId: Claims[sub] > value[1] > |
|
||||
- DownstreamTemplate: http://www.bbc.co.uk
|
||||
UpstreamTemplate: /
|
||||
UpstreamHttpMethod: Get
|
||||
|
@ -39,7 +39,8 @@
|
||||
"preserveCompilationContext": true,
|
||||
"copyToOutput": {
|
||||
"include": [
|
||||
"middlewareConfiguration.yaml"
|
||||
"middlewareConfiguration.yaml",
|
||||
"configuration.yaml"
|
||||
]
|
||||
}
|
||||
},
|
||||
@ -57,7 +58,8 @@
|
||||
"Areas/**/Views",
|
||||
"appsettings.json",
|
||||
"web.config",
|
||||
"middlewareConfiguration.yaml"
|
||||
"middlewareConfiguration.yaml",
|
||||
"configuration.yaml"
|
||||
]
|
||||
},
|
||||
|
||||
|
@ -11,8 +11,8 @@ using Ocelot.Authentication.Middleware;
|
||||
using Ocelot.Configuration.Builder;
|
||||
using Ocelot.DownstreamRouteFinder;
|
||||
using Ocelot.DownstreamRouteFinder.UrlMatcher;
|
||||
using Ocelot.Infrastructure.RequestData;
|
||||
using Ocelot.Responses;
|
||||
using Ocelot.ScopedData;
|
||||
using TestStack.BDDfy;
|
||||
using Xunit;
|
||||
|
||||
@ -20,7 +20,7 @@ namespace Ocelot.UnitTests.Authentication
|
||||
{
|
||||
public class AuthenticationMiddlewareTests : IDisposable
|
||||
{
|
||||
private readonly Mock<IScopedRequestDataRepository> _scopedRepository;
|
||||
private readonly Mock<IRequestScopedDataRepository> _scopedRepository;
|
||||
private readonly Mock<IAuthenticationHandlerFactory> _authFactory;
|
||||
private readonly string _url;
|
||||
private readonly TestServer _server;
|
||||
@ -31,7 +31,7 @@ namespace Ocelot.UnitTests.Authentication
|
||||
public AuthenticationMiddlewareTests()
|
||||
{
|
||||
_url = "http://localhost:51879";
|
||||
_scopedRepository = new Mock<IScopedRequestDataRepository>();
|
||||
_scopedRepository = new Mock<IRequestScopedDataRepository>();
|
||||
_authFactory = new Mock<IAuthenticationHandlerFactory>();
|
||||
var builder = new WebHostBuilder()
|
||||
.ConfigureServices(x =>
|
||||
|
@ -11,8 +11,8 @@ using Ocelot.Authorisation;
|
||||
using Ocelot.Configuration.Builder;
|
||||
using Ocelot.DownstreamRouteFinder;
|
||||
using Ocelot.DownstreamRouteFinder.UrlMatcher;
|
||||
using Ocelot.Infrastructure.RequestData;
|
||||
using Ocelot.Responses;
|
||||
using Ocelot.ScopedData;
|
||||
using TestStack.BDDfy;
|
||||
using Xunit;
|
||||
|
||||
@ -22,7 +22,7 @@ namespace Ocelot.UnitTests.Authorization
|
||||
|
||||
public class AuthorisationMiddlewareTests : IDisposable
|
||||
{
|
||||
private readonly Mock<IScopedRequestDataRepository> _scopedRepository;
|
||||
private readonly Mock<IRequestScopedDataRepository> _scopedRepository;
|
||||
private readonly Mock<IAuthoriser> _authService;
|
||||
private readonly string _url;
|
||||
private readonly TestServer _server;
|
||||
@ -33,7 +33,7 @@ namespace Ocelot.UnitTests.Authorization
|
||||
public AuthorisationMiddlewareTests()
|
||||
{
|
||||
_url = "http://localhost:51879";
|
||||
_scopedRepository = new Mock<IScopedRequestDataRepository>();
|
||||
_scopedRepository = new Mock<IRequestScopedDataRepository>();
|
||||
_authService = new Mock<IAuthoriser>();
|
||||
var builder = new WebHostBuilder()
|
||||
.ConfigureServices(x =>
|
||||
|
@ -1,4 +1,6 @@
|
||||
namespace Ocelot.UnitTests.ClaimsBuilder
|
||||
using Ocelot.Infrastructure.RequestData;
|
||||
|
||||
namespace Ocelot.UnitTests.ClaimsBuilder
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -16,13 +18,12 @@
|
||||
using Ocelot.DownstreamRouteFinder;
|
||||
using Ocelot.DownstreamRouteFinder.UrlMatcher;
|
||||
using Responses;
|
||||
using ScopedData;
|
||||
using TestStack.BDDfy;
|
||||
using Xunit;
|
||||
|
||||
public class ClaimsBuilderMiddlewareTests : IDisposable
|
||||
{
|
||||
private readonly Mock<IScopedRequestDataRepository> _scopedRepository;
|
||||
private readonly Mock<IRequestScopedDataRepository> _scopedRepository;
|
||||
private readonly Mock<IAddClaimsToRequest> _addHeaders;
|
||||
private readonly string _url;
|
||||
private readonly TestServer _server;
|
||||
@ -33,7 +34,7 @@
|
||||
public ClaimsBuilderMiddlewareTests()
|
||||
{
|
||||
_url = "http://localhost:51879";
|
||||
_scopedRepository = new Mock<IScopedRequestDataRepository>();
|
||||
_scopedRepository = new Mock<IRequestScopedDataRepository>();
|
||||
_addHeaders = new Mock<IAddClaimsToRequest>();
|
||||
var builder = new WebHostBuilder()
|
||||
.ConfigureServices(x =>
|
||||
|
@ -11,8 +11,8 @@ using Ocelot.DownstreamRouteFinder;
|
||||
using Ocelot.DownstreamRouteFinder.Finder;
|
||||
using Ocelot.DownstreamRouteFinder.Middleware;
|
||||
using Ocelot.DownstreamRouteFinder.UrlMatcher;
|
||||
using Ocelot.Infrastructure.RequestData;
|
||||
using Ocelot.Responses;
|
||||
using Ocelot.ScopedData;
|
||||
using TestStack.BDDfy;
|
||||
using Xunit;
|
||||
|
||||
@ -21,7 +21,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
public class DownstreamRouteFinderMiddlewareTests : IDisposable
|
||||
{
|
||||
private readonly Mock<IDownstreamRouteFinder> _downstreamRouteFinder;
|
||||
private readonly Mock<IScopedRequestDataRepository> _scopedRepository;
|
||||
private readonly Mock<IRequestScopedDataRepository> _scopedRepository;
|
||||
private readonly string _url;
|
||||
private readonly TestServer _server;
|
||||
private readonly HttpClient _client;
|
||||
@ -32,7 +32,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
{
|
||||
_url = "http://localhost:51879";
|
||||
_downstreamRouteFinder = new Mock<IDownstreamRouteFinder>();
|
||||
_scopedRepository = new Mock<IScopedRequestDataRepository>();
|
||||
_scopedRepository = new Mock<IRequestScopedDataRepository>();
|
||||
|
||||
var builder = new WebHostBuilder()
|
||||
.ConfigureServices(x =>
|
||||
|
@ -11,8 +11,8 @@ using Ocelot.DownstreamRouteFinder;
|
||||
using Ocelot.DownstreamRouteFinder.UrlMatcher;
|
||||
using Ocelot.DownstreamUrlCreator.Middleware;
|
||||
using Ocelot.DownstreamUrlCreator.UrlTemplateReplacer;
|
||||
using Ocelot.Infrastructure.RequestData;
|
||||
using Ocelot.Responses;
|
||||
using Ocelot.ScopedData;
|
||||
using TestStack.BDDfy;
|
||||
using Xunit;
|
||||
|
||||
@ -21,7 +21,7 @@ namespace Ocelot.UnitTests.DownstreamUrlCreator
|
||||
public class DownstreamUrlCreatorMiddlewareTests : IDisposable
|
||||
{
|
||||
private readonly Mock<IDownstreamUrlTemplateVariableReplacer> _downstreamUrlTemplateVariableReplacer;
|
||||
private readonly Mock<IScopedRequestDataRepository> _scopedRepository;
|
||||
private readonly Mock<IRequestScopedDataRepository> _scopedRepository;
|
||||
private readonly string _url;
|
||||
private readonly TestServer _server;
|
||||
private readonly HttpClient _client;
|
||||
@ -33,7 +33,7 @@ namespace Ocelot.UnitTests.DownstreamUrlCreator
|
||||
{
|
||||
_url = "http://localhost:51879";
|
||||
_downstreamUrlTemplateVariableReplacer = new Mock<IDownstreamUrlTemplateVariableReplacer>();
|
||||
_scopedRepository = new Mock<IScopedRequestDataRepository>();
|
||||
_scopedRepository = new Mock<IRequestScopedDataRepository>();
|
||||
|
||||
var builder = new WebHostBuilder()
|
||||
.ConfigureServices(x =>
|
||||
|
@ -13,8 +13,8 @@ using Ocelot.DownstreamRouteFinder;
|
||||
using Ocelot.DownstreamRouteFinder.UrlMatcher;
|
||||
using Ocelot.HeaderBuilder;
|
||||
using Ocelot.HeaderBuilder.Middleware;
|
||||
using Ocelot.Infrastructure.RequestData;
|
||||
using Ocelot.Responses;
|
||||
using Ocelot.ScopedData;
|
||||
using TestStack.BDDfy;
|
||||
using Xunit;
|
||||
|
||||
@ -22,7 +22,7 @@ namespace Ocelot.UnitTests.HeaderBuilder
|
||||
{
|
||||
public class HttpRequestHeadersBuilderMiddlewareTests : IDisposable
|
||||
{
|
||||
private readonly Mock<IScopedRequestDataRepository> _scopedRepository;
|
||||
private readonly Mock<IRequestScopedDataRepository> _scopedRepository;
|
||||
private readonly Mock<IAddHeadersToRequest> _addHeaders;
|
||||
private readonly string _url;
|
||||
private readonly TestServer _server;
|
||||
@ -33,7 +33,7 @@ namespace Ocelot.UnitTests.HeaderBuilder
|
||||
public HttpRequestHeadersBuilderMiddlewareTests()
|
||||
{
|
||||
_url = "http://localhost:51879";
|
||||
_scopedRepository = new Mock<IScopedRequestDataRepository>();
|
||||
_scopedRepository = new Mock<IRequestScopedDataRepository>();
|
||||
_addHeaders = new Mock<IAddHeadersToRequest>();
|
||||
var builder = new WebHostBuilder()
|
||||
.ConfigureServices(x =>
|
||||
|
@ -1,6 +1,6 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Ocelot.Infrastructure.RequestData;
|
||||
using Ocelot.Responses;
|
||||
using Ocelot.ScopedData;
|
||||
using Shouldly;
|
||||
using TestStack.BDDfy;
|
||||
using Xunit;
|
||||
@ -9,7 +9,7 @@ namespace Ocelot.UnitTests.Repository
|
||||
{
|
||||
public class ScopedRequestDataRepositoryTests
|
||||
{
|
||||
private IScopedRequestDataRepository _scopedRequestDataRepository;
|
||||
private IRequestScopedDataRepository _requestScopedDataRepository;
|
||||
private IHttpContextAccessor _httpContextAccesor;
|
||||
private string _key;
|
||||
private object _toAdd;
|
||||
@ -19,7 +19,7 @@ namespace Ocelot.UnitTests.Repository
|
||||
{
|
||||
_httpContextAccesor = new HttpContextAccessor();
|
||||
_httpContextAccesor.HttpContext = new DefaultHttpContext();
|
||||
_scopedRequestDataRepository = new ScopedRequestDataRepository(_httpContextAccesor);
|
||||
_requestScopedDataRepository = new HttpDataRepository(_httpContextAccesor);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@ -48,7 +48,7 @@ namespace Ocelot.UnitTests.Repository
|
||||
|
||||
private void WhenIGetTheItem()
|
||||
{
|
||||
_result = _scopedRequestDataRepository.Get<int[]>(_key);
|
||||
_result = _requestScopedDataRepository.Get<int[]>(_key);
|
||||
}
|
||||
|
||||
private void GivenThereIsAnItemInTheContext(string key)
|
||||
@ -66,7 +66,7 @@ namespace Ocelot.UnitTests.Repository
|
||||
|
||||
private void WhenIAddTheItem()
|
||||
{
|
||||
_scopedRequestDataRepository.Add(_key, _toAdd);
|
||||
_requestScopedDataRepository.Add(_key, _toAdd);
|
||||
}
|
||||
|
||||
private void ThenTheItemIsAdded()
|
||||
|
@ -7,11 +7,11 @@ using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.TestHost;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Moq;
|
||||
using Ocelot.Infrastructure.RequestData;
|
||||
using Ocelot.RequestBuilder;
|
||||
using Ocelot.RequestBuilder.Builder;
|
||||
using Ocelot.RequestBuilder.Middleware;
|
||||
using Ocelot.Responses;
|
||||
using Ocelot.ScopedData;
|
||||
using TestStack.BDDfy;
|
||||
using Xunit;
|
||||
|
||||
@ -20,7 +20,7 @@ namespace Ocelot.UnitTests.RequestBuilder
|
||||
public class HttpRequestBuilderMiddlewareTests : IDisposable
|
||||
{
|
||||
private readonly Mock<IRequestBuilder> _requestBuilder;
|
||||
private readonly Mock<IScopedRequestDataRepository> _scopedRepository;
|
||||
private readonly Mock<IRequestScopedDataRepository> _scopedRepository;
|
||||
private readonly string _url;
|
||||
private readonly TestServer _server;
|
||||
private readonly HttpClient _client;
|
||||
@ -32,7 +32,7 @@ namespace Ocelot.UnitTests.RequestBuilder
|
||||
{
|
||||
_url = "http://localhost:51879";
|
||||
_requestBuilder = new Mock<IRequestBuilder>();
|
||||
_scopedRepository = new Mock<IScopedRequestDataRepository>();
|
||||
_scopedRepository = new Mock<IRequestScopedDataRepository>();
|
||||
|
||||
var builder = new WebHostBuilder()
|
||||
.ConfigureServices(x =>
|
||||
|
@ -6,11 +6,11 @@ using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.TestHost;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Moq;
|
||||
using Ocelot.Infrastructure.RequestData;
|
||||
using Ocelot.RequestBuilder;
|
||||
using Ocelot.Requester;
|
||||
using Ocelot.Requester.Middleware;
|
||||
using Ocelot.Responses;
|
||||
using Ocelot.ScopedData;
|
||||
using TestStack.BDDfy;
|
||||
using Xunit;
|
||||
|
||||
@ -19,7 +19,7 @@ namespace Ocelot.UnitTests.Requester
|
||||
public class HttpRequesterMiddlewareTests : IDisposable
|
||||
{
|
||||
private readonly Mock<IHttpRequester> _requester;
|
||||
private readonly Mock<IScopedRequestDataRepository> _scopedRepository;
|
||||
private readonly Mock<IRequestScopedDataRepository> _scopedRepository;
|
||||
private readonly string _url;
|
||||
private readonly TestServer _server;
|
||||
private readonly HttpClient _client;
|
||||
@ -31,7 +31,7 @@ namespace Ocelot.UnitTests.Requester
|
||||
{
|
||||
_url = "http://localhost:51879";
|
||||
_requester = new Mock<IHttpRequester>();
|
||||
_scopedRepository = new Mock<IScopedRequestDataRepository>();
|
||||
_scopedRepository = new Mock<IRequestScopedDataRepository>();
|
||||
|
||||
var builder = new WebHostBuilder()
|
||||
.ConfigureServices(x =>
|
||||
|
@ -6,10 +6,10 @@ using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.TestHost;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Moq;
|
||||
using Ocelot.Infrastructure.RequestData;
|
||||
using Ocelot.Responder;
|
||||
using Ocelot.Responder.Middleware;
|
||||
using Ocelot.Responses;
|
||||
using Ocelot.ScopedData;
|
||||
using TestStack.BDDfy;
|
||||
using Xunit;
|
||||
|
||||
@ -18,7 +18,7 @@ namespace Ocelot.UnitTests.Responder
|
||||
public class HttpResponderMiddlewareTests : IDisposable
|
||||
{
|
||||
private readonly Mock<IHttpResponder> _responder;
|
||||
private readonly Mock<IScopedRequestDataRepository> _scopedRepository;
|
||||
private readonly Mock<IRequestScopedDataRepository> _scopedRepository;
|
||||
private readonly Mock<IErrorsToHttpStatusCodeMapper> _codeMapper;
|
||||
private readonly string _url;
|
||||
private readonly TestServer _server;
|
||||
@ -30,7 +30,7 @@ namespace Ocelot.UnitTests.Responder
|
||||
{
|
||||
_url = "http://localhost:51879";
|
||||
_responder = new Mock<IHttpResponder>();
|
||||
_scopedRepository = new Mock<IScopedRequestDataRepository>();
|
||||
_scopedRepository = new Mock<IRequestScopedDataRepository>();
|
||||
_codeMapper = new Mock<IErrorsToHttpStatusCodeMapper>();
|
||||
|
||||
var builder = new WebHostBuilder()
|
||||
|
Loading…
x
Reference in New Issue
Block a user