mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-04-22 06:42:50 +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.Configuration;
|
||||||
using Ocelot.DownstreamRouteFinder;
|
using Ocelot.DownstreamRouteFinder;
|
||||||
using Ocelot.Errors;
|
using Ocelot.Errors;
|
||||||
|
using Ocelot.Infrastructure.RequestData;
|
||||||
using Ocelot.Middleware;
|
using Ocelot.Middleware;
|
||||||
using Ocelot.ScopedData;
|
|
||||||
|
|
||||||
namespace Ocelot.Authentication.Middleware
|
namespace Ocelot.Authentication.Middleware
|
||||||
{
|
{
|
||||||
public class AuthenticationMiddleware : OcelotMiddleware
|
public class AuthenticationMiddleware : OcelotMiddleware
|
||||||
{
|
{
|
||||||
private readonly RequestDelegate _next;
|
private readonly RequestDelegate _next;
|
||||||
private readonly IScopedRequestDataRepository _scopedRequestDataRepository;
|
private readonly IRequestScopedDataRepository _requestScopedDataRepository;
|
||||||
private readonly IApplicationBuilder _app;
|
private readonly IApplicationBuilder _app;
|
||||||
private readonly IAuthenticationHandlerFactory _authHandlerFactory;
|
private readonly IAuthenticationHandlerFactory _authHandlerFactory;
|
||||||
|
|
||||||
public AuthenticationMiddleware(RequestDelegate next, IApplicationBuilder app,
|
public AuthenticationMiddleware(RequestDelegate next,
|
||||||
IScopedRequestDataRepository scopedRequestDataRepository, IAuthenticationHandlerFactory authHandlerFactory)
|
IApplicationBuilder app,
|
||||||
: base(scopedRequestDataRepository)
|
IRequestScopedDataRepository requestScopedDataRepository,
|
||||||
|
IAuthenticationHandlerFactory authHandlerFactory)
|
||||||
|
: base(requestScopedDataRepository)
|
||||||
{
|
{
|
||||||
_next = next;
|
_next = next;
|
||||||
_scopedRequestDataRepository = scopedRequestDataRepository;
|
_requestScopedDataRepository = requestScopedDataRepository;
|
||||||
_authHandlerFactory = authHandlerFactory;
|
_authHandlerFactory = authHandlerFactory;
|
||||||
_app = app;
|
_app = app;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task Invoke(HttpContext context)
|
public async Task Invoke(HttpContext context)
|
||||||
{
|
{
|
||||||
var downstreamRoute = _scopedRequestDataRepository.Get<DownstreamRoute>("DownstreamRoute");
|
var downstreamRoute = _requestScopedDataRepository.Get<DownstreamRoute>("DownstreamRoute");
|
||||||
|
|
||||||
if (downstreamRoute.IsError)
|
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.Collections.Generic;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@ -6,27 +8,26 @@
|
|||||||
using Errors;
|
using Errors;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Ocelot.Middleware;
|
using Ocelot.Middleware;
|
||||||
using ScopedData;
|
|
||||||
|
|
||||||
public class AuthorisationMiddleware : OcelotMiddleware
|
public class AuthorisationMiddleware : OcelotMiddleware
|
||||||
{
|
{
|
||||||
private readonly RequestDelegate _next;
|
private readonly RequestDelegate _next;
|
||||||
private readonly IScopedRequestDataRepository _scopedRequestDataRepository;
|
private readonly IRequestScopedDataRepository _requestScopedDataRepository;
|
||||||
private readonly IAuthoriser _authoriser;
|
private readonly IAuthoriser _authoriser;
|
||||||
|
|
||||||
public AuthorisationMiddleware(RequestDelegate next,
|
public AuthorisationMiddleware(RequestDelegate next,
|
||||||
IScopedRequestDataRepository scopedRequestDataRepository,
|
IRequestScopedDataRepository requestScopedDataRepository,
|
||||||
IAuthoriser authoriser)
|
IAuthoriser authoriser)
|
||||||
: base(scopedRequestDataRepository)
|
: base(requestScopedDataRepository)
|
||||||
{
|
{
|
||||||
_next = next;
|
_next = next;
|
||||||
_scopedRequestDataRepository = scopedRequestDataRepository;
|
_requestScopedDataRepository = requestScopedDataRepository;
|
||||||
_authoriser = authoriser;
|
_authoriser = authoriser;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task Invoke(HttpContext context)
|
public async Task Invoke(HttpContext context)
|
||||||
{
|
{
|
||||||
var downstreamRoute = _scopedRequestDataRepository.Get<DownstreamRoute>("DownstreamRoute");
|
var downstreamRoute = _requestScopedDataRepository.Get<DownstreamRoute>("DownstreamRoute");
|
||||||
|
|
||||||
if (downstreamRoute.IsError)
|
if (downstreamRoute.IsError)
|
||||||
{
|
{
|
||||||
|
@ -1,31 +1,32 @@
|
|||||||
namespace Ocelot.ClaimsBuilder.Middleware
|
using Ocelot.Infrastructure.RequestData;
|
||||||
|
|
||||||
|
namespace Ocelot.ClaimsBuilder.Middleware
|
||||||
{
|
{
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using DownstreamRouteFinder;
|
using DownstreamRouteFinder;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Ocelot.Middleware;
|
using Ocelot.Middleware;
|
||||||
using ScopedData;
|
|
||||||
|
|
||||||
public class ClaimsBuilderMiddleware : OcelotMiddleware
|
public class ClaimsBuilderMiddleware : OcelotMiddleware
|
||||||
{
|
{
|
||||||
private readonly RequestDelegate _next;
|
private readonly RequestDelegate _next;
|
||||||
private readonly IAddClaimsToRequest _addClaimsToRequest;
|
private readonly IAddClaimsToRequest _addClaimsToRequest;
|
||||||
private readonly IScopedRequestDataRepository _scopedRequestDataRepository;
|
private readonly IRequestScopedDataRepository _requestScopedDataRepository;
|
||||||
|
|
||||||
public ClaimsBuilderMiddleware(RequestDelegate next,
|
public ClaimsBuilderMiddleware(RequestDelegate next,
|
||||||
IScopedRequestDataRepository scopedRequestDataRepository,
|
IRequestScopedDataRepository requestScopedDataRepository,
|
||||||
IAddClaimsToRequest addClaimsToRequest)
|
IAddClaimsToRequest addClaimsToRequest)
|
||||||
: base(scopedRequestDataRepository)
|
: base(requestScopedDataRepository)
|
||||||
{
|
{
|
||||||
_next = next;
|
_next = next;
|
||||||
_addClaimsToRequest = addClaimsToRequest;
|
_addClaimsToRequest = addClaimsToRequest;
|
||||||
_scopedRequestDataRepository = scopedRequestDataRepository;
|
_requestScopedDataRepository = requestScopedDataRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task Invoke(HttpContext context)
|
public async Task Invoke(HttpContext context)
|
||||||
{
|
{
|
||||||
var downstreamRoute = _scopedRequestDataRepository.Get<DownstreamRoute>("DownstreamRoute");
|
var downstreamRoute = _requestScopedDataRepository.Get<DownstreamRoute>("DownstreamRoute");
|
||||||
|
|
||||||
if (downstreamRoute.Data.ReRoute.ClaimsToClaims.Any())
|
if (downstreamRoute.Data.ReRoute.ClaimsToClaims.Any())
|
||||||
{
|
{
|
||||||
|
@ -65,20 +65,19 @@ namespace Ocelot.Configuration.Validator
|
|||||||
|
|
||||||
private ConfigurationValidationResult CheckForDupliateReRoutes(YamlConfiguration configuration)
|
private ConfigurationValidationResult CheckForDupliateReRoutes(YamlConfiguration configuration)
|
||||||
{
|
{
|
||||||
var duplicateUpstreamTemplates = configuration.ReRoutes
|
var hasDupes = configuration.ReRoutes
|
||||||
.Select(r => r.DownstreamTemplate)
|
.GroupBy(x => new { x.UpstreamTemplate, x.UpstreamHttpMethod }).Any(x => x.Skip(1).Any());
|
||||||
.GroupBy(r => r)
|
|
||||||
.Where(r => r.Count() > 1)
|
|
||||||
.Select(r => r.Key)
|
|
||||||
.ToList();
|
|
||||||
|
|
||||||
if (duplicateUpstreamTemplates.Count <= 0)
|
if (!hasDupes)
|
||||||
{
|
{
|
||||||
return new ConfigurationValidationResult(false);
|
return new ConfigurationValidationResult(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
var errors = duplicateUpstreamTemplates
|
var dupes = configuration.ReRoutes.GroupBy(x => new { x.UpstreamTemplate, x.UpstreamHttpMethod })
|
||||||
.Select(duplicateUpstreamTemplate => new DownstreamTemplateAlreadyUsedError(string.Format("Duplicate DownstreamTemplate: {0}", duplicateUpstreamTemplate)))
|
.Where(x => x.Skip(1).Any());
|
||||||
|
|
||||||
|
var errors = dupes
|
||||||
|
.Select(d => new DownstreamTemplateAlreadyUsedError(string.Format("Duplicate DownstreamTemplate: {0}", d.Key.UpstreamTemplate)))
|
||||||
.Cast<Error>()
|
.Cast<Error>()
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
|
@ -15,10 +15,10 @@ using Ocelot.DownstreamRouteFinder.Finder;
|
|||||||
using Ocelot.DownstreamRouteFinder.UrlMatcher;
|
using Ocelot.DownstreamRouteFinder.UrlMatcher;
|
||||||
using Ocelot.DownstreamUrlCreator.UrlTemplateReplacer;
|
using Ocelot.DownstreamUrlCreator.UrlTemplateReplacer;
|
||||||
using Ocelot.HeaderBuilder;
|
using Ocelot.HeaderBuilder;
|
||||||
|
using Ocelot.Infrastructure.RequestData;
|
||||||
using Ocelot.RequestBuilder.Builder;
|
using Ocelot.RequestBuilder.Builder;
|
||||||
using Ocelot.Requester;
|
using Ocelot.Requester;
|
||||||
using Ocelot.Responder;
|
using Ocelot.Responder;
|
||||||
using Ocelot.ScopedData;
|
|
||||||
|
|
||||||
namespace Ocelot.DependencyInjection
|
namespace Ocelot.DependencyInjection
|
||||||
{
|
{
|
||||||
@ -44,7 +44,7 @@ namespace Ocelot.DependencyInjection
|
|||||||
|
|
||||||
public static IServiceCollection AddOcelot(this IServiceCollection services)
|
public static IServiceCollection AddOcelot(this IServiceCollection services)
|
||||||
{
|
{
|
||||||
// framework services
|
// framework services dependency for the identity server middleware
|
||||||
services.AddMvcCore().AddJsonFormatters();
|
services.AddMvcCore().AddJsonFormatters();
|
||||||
services.AddLogging();
|
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
|
// 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
|
// could maybe use a scoped data repository
|
||||||
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
|
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
|
||||||
services.AddScoped<IScopedRequestDataRepository, ScopedRequestDataRepository>();
|
services.AddScoped<IRequestScopedDataRepository, HttpDataRepository>();
|
||||||
|
|
||||||
return services;
|
return services;
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Ocelot.DownstreamRouteFinder.Finder;
|
using Ocelot.DownstreamRouteFinder.Finder;
|
||||||
|
using Ocelot.Infrastructure.RequestData;
|
||||||
using Ocelot.Middleware;
|
using Ocelot.Middleware;
|
||||||
using Ocelot.ScopedData;
|
|
||||||
|
|
||||||
namespace Ocelot.DownstreamRouteFinder.Middleware
|
namespace Ocelot.DownstreamRouteFinder.Middleware
|
||||||
{
|
{
|
||||||
@ -10,16 +10,16 @@ namespace Ocelot.DownstreamRouteFinder.Middleware
|
|||||||
{
|
{
|
||||||
private readonly RequestDelegate _next;
|
private readonly RequestDelegate _next;
|
||||||
private readonly IDownstreamRouteFinder _downstreamRouteFinder;
|
private readonly IDownstreamRouteFinder _downstreamRouteFinder;
|
||||||
private readonly IScopedRequestDataRepository _scopedRequestDataRepository;
|
private readonly IRequestScopedDataRepository _requestScopedDataRepository;
|
||||||
|
|
||||||
public DownstreamRouteFinderMiddleware(RequestDelegate next,
|
public DownstreamRouteFinderMiddleware(RequestDelegate next,
|
||||||
IDownstreamRouteFinder downstreamRouteFinder,
|
IDownstreamRouteFinder downstreamRouteFinder,
|
||||||
IScopedRequestDataRepository scopedRequestDataRepository)
|
IRequestScopedDataRepository requestScopedDataRepository)
|
||||||
:base(scopedRequestDataRepository)
|
:base(requestScopedDataRepository)
|
||||||
{
|
{
|
||||||
_next = next;
|
_next = next;
|
||||||
_downstreamRouteFinder = downstreamRouteFinder;
|
_downstreamRouteFinder = downstreamRouteFinder;
|
||||||
_scopedRequestDataRepository = scopedRequestDataRepository;
|
_requestScopedDataRepository = requestScopedDataRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task Invoke(HttpContext context)
|
public async Task Invoke(HttpContext context)
|
||||||
@ -34,7 +34,7 @@ namespace Ocelot.DownstreamRouteFinder.Middleware
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_scopedRequestDataRepository.Add("DownstreamRoute", downstreamRoute.Data);
|
_requestScopedDataRepository.Add("DownstreamRoute", downstreamRoute.Data);
|
||||||
|
|
||||||
await _next.Invoke(context);
|
await _next.Invoke(context);
|
||||||
}
|
}
|
||||||
|
@ -2,8 +2,8 @@ using System.Threading.Tasks;
|
|||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Ocelot.DownstreamRouteFinder;
|
using Ocelot.DownstreamRouteFinder;
|
||||||
using Ocelot.DownstreamUrlCreator.UrlTemplateReplacer;
|
using Ocelot.DownstreamUrlCreator.UrlTemplateReplacer;
|
||||||
|
using Ocelot.Infrastructure.RequestData;
|
||||||
using Ocelot.Middleware;
|
using Ocelot.Middleware;
|
||||||
using Ocelot.ScopedData;
|
|
||||||
|
|
||||||
namespace Ocelot.DownstreamUrlCreator.Middleware
|
namespace Ocelot.DownstreamUrlCreator.Middleware
|
||||||
{
|
{
|
||||||
@ -11,21 +11,21 @@ namespace Ocelot.DownstreamUrlCreator.Middleware
|
|||||||
{
|
{
|
||||||
private readonly RequestDelegate _next;
|
private readonly RequestDelegate _next;
|
||||||
private readonly IDownstreamUrlTemplateVariableReplacer _urlReplacer;
|
private readonly IDownstreamUrlTemplateVariableReplacer _urlReplacer;
|
||||||
private readonly IScopedRequestDataRepository _scopedRequestDataRepository;
|
private readonly IRequestScopedDataRepository _requestScopedDataRepository;
|
||||||
|
|
||||||
public DownstreamUrlCreatorMiddleware(RequestDelegate next,
|
public DownstreamUrlCreatorMiddleware(RequestDelegate next,
|
||||||
IDownstreamUrlTemplateVariableReplacer urlReplacer,
|
IDownstreamUrlTemplateVariableReplacer urlReplacer,
|
||||||
IScopedRequestDataRepository scopedRequestDataRepository)
|
IRequestScopedDataRepository requestScopedDataRepository)
|
||||||
:base(scopedRequestDataRepository)
|
:base(requestScopedDataRepository)
|
||||||
{
|
{
|
||||||
_next = next;
|
_next = next;
|
||||||
_urlReplacer = urlReplacer;
|
_urlReplacer = urlReplacer;
|
||||||
_scopedRequestDataRepository = scopedRequestDataRepository;
|
_requestScopedDataRepository = requestScopedDataRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task Invoke(HttpContext context)
|
public async Task Invoke(HttpContext context)
|
||||||
{
|
{
|
||||||
var downstreamRoute = _scopedRequestDataRepository.Get<DownstreamRoute>("DownstreamRoute");
|
var downstreamRoute = _requestScopedDataRepository.Get<DownstreamRoute>("DownstreamRoute");
|
||||||
|
|
||||||
if (downstreamRoute.IsError)
|
if (downstreamRoute.IsError)
|
||||||
{
|
{
|
||||||
@ -41,7 +41,7 @@ namespace Ocelot.DownstreamUrlCreator.Middleware
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_scopedRequestDataRepository.Add("DownstreamUrl", downstreamUrl.Data);
|
_requestScopedDataRepository.Add("DownstreamUrl", downstreamUrl.Data);
|
||||||
|
|
||||||
await _next.Invoke(context);
|
await _next.Invoke(context);
|
||||||
}
|
}
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Ocelot.DownstreamRouteFinder;
|
using Ocelot.DownstreamRouteFinder;
|
||||||
|
using Ocelot.Infrastructure.RequestData;
|
||||||
using Ocelot.Middleware;
|
using Ocelot.Middleware;
|
||||||
using Ocelot.ScopedData;
|
|
||||||
|
|
||||||
namespace Ocelot.HeaderBuilder.Middleware
|
namespace Ocelot.HeaderBuilder.Middleware
|
||||||
{
|
{
|
||||||
@ -11,21 +11,21 @@ namespace Ocelot.HeaderBuilder.Middleware
|
|||||||
{
|
{
|
||||||
private readonly RequestDelegate _next;
|
private readonly RequestDelegate _next;
|
||||||
private readonly IAddHeadersToRequest _addHeadersToRequest;
|
private readonly IAddHeadersToRequest _addHeadersToRequest;
|
||||||
private readonly IScopedRequestDataRepository _scopedRequestDataRepository;
|
private readonly IRequestScopedDataRepository _requestScopedDataRepository;
|
||||||
|
|
||||||
public HttpRequestHeadersBuilderMiddleware(RequestDelegate next,
|
public HttpRequestHeadersBuilderMiddleware(RequestDelegate next,
|
||||||
IScopedRequestDataRepository scopedRequestDataRepository,
|
IRequestScopedDataRepository requestScopedDataRepository,
|
||||||
IAddHeadersToRequest addHeadersToRequest)
|
IAddHeadersToRequest addHeadersToRequest)
|
||||||
: base(scopedRequestDataRepository)
|
: base(requestScopedDataRepository)
|
||||||
{
|
{
|
||||||
_next = next;
|
_next = next;
|
||||||
_addHeadersToRequest = addHeadersToRequest;
|
_addHeadersToRequest = addHeadersToRequest;
|
||||||
_scopedRequestDataRepository = scopedRequestDataRepository;
|
_requestScopedDataRepository = requestScopedDataRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task Invoke(HttpContext context)
|
public async Task Invoke(HttpContext context)
|
||||||
{
|
{
|
||||||
var downstreamRoute = _scopedRequestDataRepository.Get<DownstreamRoute>("DownstreamRoute");
|
var downstreamRoute = _requestScopedDataRepository.Get<DownstreamRoute>("DownstreamRoute");
|
||||||
|
|
||||||
if (downstreamRoute.Data.ReRoute.ClaimsToHeaders.Any())
|
if (downstreamRoute.Data.ReRoute.ClaimsToHeaders.Any())
|
||||||
{
|
{
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
using Ocelot.Errors;
|
using Ocelot.Errors;
|
||||||
|
|
||||||
namespace Ocelot.ScopedData
|
namespace Ocelot.Infrastructure.RequestData
|
||||||
{
|
{
|
||||||
public class CannotAddDataError : Error
|
public class CannotAddDataError : Error
|
||||||
{
|
{
|
@ -1,6 +1,6 @@
|
|||||||
using Ocelot.Errors;
|
using Ocelot.Errors;
|
||||||
|
|
||||||
namespace Ocelot.ScopedData
|
namespace Ocelot.Infrastructure.RequestData
|
||||||
{
|
{
|
||||||
public class CannotFindDataError : Error
|
public class CannotFindDataError : Error
|
||||||
{
|
{
|
@ -4,13 +4,13 @@ using Microsoft.AspNetCore.Http;
|
|||||||
using Ocelot.Errors;
|
using Ocelot.Errors;
|
||||||
using Ocelot.Responses;
|
using Ocelot.Responses;
|
||||||
|
|
||||||
namespace Ocelot.ScopedData
|
namespace Ocelot.Infrastructure.RequestData
|
||||||
{
|
{
|
||||||
public class ScopedRequestDataRepository : IScopedRequestDataRepository
|
public class HttpDataRepository : IRequestScopedDataRepository
|
||||||
{
|
{
|
||||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||||
|
|
||||||
public ScopedRequestDataRepository(IHttpContextAccessor httpContextAccessor)
|
public HttpDataRepository(IHttpContextAccessor httpContextAccessor)
|
||||||
{
|
{
|
||||||
_httpContextAccessor = httpContextAccessor;
|
_httpContextAccessor = httpContextAccessor;
|
||||||
}
|
}
|
@ -1,8 +1,8 @@
|
|||||||
using Ocelot.Responses;
|
using Ocelot.Responses;
|
||||||
|
|
||||||
namespace Ocelot.ScopedData
|
namespace Ocelot.Infrastructure.RequestData
|
||||||
{
|
{
|
||||||
public interface IScopedRequestDataRepository
|
public interface IRequestScopedDataRepository
|
||||||
{
|
{
|
||||||
Response Add<T>(string key, T value);
|
Response Add<T>(string key, T value);
|
||||||
Response<T> Get<T>(string key);
|
Response<T> Get<T>(string key);
|
@ -1,33 +1,33 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Ocelot.Errors;
|
using Ocelot.Errors;
|
||||||
using Ocelot.ScopedData;
|
using Ocelot.Infrastructure.RequestData;
|
||||||
|
|
||||||
namespace Ocelot.Middleware
|
namespace Ocelot.Middleware
|
||||||
{
|
{
|
||||||
public abstract class OcelotMiddleware
|
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)
|
public void SetPipelineError(List<Error> errors)
|
||||||
{
|
{
|
||||||
_scopedRequestDataRepository.Add("OcelotMiddlewareError", true);
|
_requestScopedDataRepository.Add("OcelotMiddlewareError", true);
|
||||||
_scopedRequestDataRepository.Add("OcelotMiddlewareErrors", errors);
|
_requestScopedDataRepository.Add("OcelotMiddlewareErrors", errors);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool PipelineError()
|
public bool PipelineError()
|
||||||
{
|
{
|
||||||
var response = _scopedRequestDataRepository.Get<bool>("OcelotMiddlewareError");
|
var response = _requestScopedDataRepository.Get<bool>("OcelotMiddlewareError");
|
||||||
return response.Data;
|
return response.Data;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Error> GetPipelineErrors()
|
public List<Error> GetPipelineErrors()
|
||||||
{
|
{
|
||||||
var response = _scopedRequestDataRepository.Get<List<Error>>("OcelotMiddlewareErrors");
|
var response = _requestScopedDataRepository.Get<List<Error>>("OcelotMiddlewareErrors");
|
||||||
return response.Data;
|
return response.Data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,30 +1,30 @@
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Ocelot.Infrastructure.RequestData;
|
||||||
using Ocelot.Middleware;
|
using Ocelot.Middleware;
|
||||||
using Ocelot.RequestBuilder.Builder;
|
using Ocelot.RequestBuilder.Builder;
|
||||||
using Ocelot.ScopedData;
|
|
||||||
|
|
||||||
namespace Ocelot.RequestBuilder.Middleware
|
namespace Ocelot.RequestBuilder.Middleware
|
||||||
{
|
{
|
||||||
public class HttpRequestBuilderMiddleware : OcelotMiddleware
|
public class HttpRequestBuilderMiddleware : OcelotMiddleware
|
||||||
{
|
{
|
||||||
private readonly RequestDelegate _next;
|
private readonly RequestDelegate _next;
|
||||||
private readonly IScopedRequestDataRepository _scopedRequestDataRepository;
|
private readonly IRequestScopedDataRepository _requestScopedDataRepository;
|
||||||
private readonly IRequestBuilder _requestBuilder;
|
private readonly IRequestBuilder _requestBuilder;
|
||||||
|
|
||||||
public HttpRequestBuilderMiddleware(RequestDelegate next,
|
public HttpRequestBuilderMiddleware(RequestDelegate next,
|
||||||
IScopedRequestDataRepository scopedRequestDataRepository,
|
IRequestScopedDataRepository requestScopedDataRepository,
|
||||||
IRequestBuilder requestBuilder)
|
IRequestBuilder requestBuilder)
|
||||||
:base(scopedRequestDataRepository)
|
:base(requestScopedDataRepository)
|
||||||
{
|
{
|
||||||
_next = next;
|
_next = next;
|
||||||
_scopedRequestDataRepository = scopedRequestDataRepository;
|
_requestScopedDataRepository = requestScopedDataRepository;
|
||||||
_requestBuilder = requestBuilder;
|
_requestBuilder = requestBuilder;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task Invoke(HttpContext context)
|
public async Task Invoke(HttpContext context)
|
||||||
{
|
{
|
||||||
var downstreamUrl = _scopedRequestDataRepository.Get<string>("DownstreamUrl");
|
var downstreamUrl = _requestScopedDataRepository.Get<string>("DownstreamUrl");
|
||||||
|
|
||||||
if (downstreamUrl.IsError)
|
if (downstreamUrl.IsError)
|
||||||
{
|
{
|
||||||
@ -42,7 +42,7 @@ namespace Ocelot.RequestBuilder.Middleware
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_scopedRequestDataRepository.Add("Request", request.Data);
|
_requestScopedDataRepository.Add("Request", request.Data);
|
||||||
|
|
||||||
await _next.Invoke(context);
|
await _next.Invoke(context);
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Ocelot.Infrastructure.RequestData;
|
||||||
using Ocelot.Middleware;
|
using Ocelot.Middleware;
|
||||||
using Ocelot.RequestBuilder;
|
using Ocelot.RequestBuilder;
|
||||||
using Ocelot.ScopedData;
|
|
||||||
|
|
||||||
namespace Ocelot.Requester.Middleware
|
namespace Ocelot.Requester.Middleware
|
||||||
{
|
{
|
||||||
@ -10,21 +10,21 @@ namespace Ocelot.Requester.Middleware
|
|||||||
{
|
{
|
||||||
private readonly RequestDelegate _next;
|
private readonly RequestDelegate _next;
|
||||||
private readonly IHttpRequester _requester;
|
private readonly IHttpRequester _requester;
|
||||||
private readonly IScopedRequestDataRepository _scopedRequestDataRepository;
|
private readonly IRequestScopedDataRepository _requestScopedDataRepository;
|
||||||
|
|
||||||
public HttpRequesterMiddleware(RequestDelegate next,
|
public HttpRequesterMiddleware(RequestDelegate next,
|
||||||
IHttpRequester requester,
|
IHttpRequester requester,
|
||||||
IScopedRequestDataRepository scopedRequestDataRepository)
|
IRequestScopedDataRepository requestScopedDataRepository)
|
||||||
:base(scopedRequestDataRepository)
|
:base(requestScopedDataRepository)
|
||||||
{
|
{
|
||||||
_next = next;
|
_next = next;
|
||||||
_requester = requester;
|
_requester = requester;
|
||||||
_scopedRequestDataRepository = scopedRequestDataRepository;
|
_requestScopedDataRepository = requestScopedDataRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task Invoke(HttpContext context)
|
public async Task Invoke(HttpContext context)
|
||||||
{
|
{
|
||||||
var request = _scopedRequestDataRepository.Get<Request>("Request");
|
var request = _requestScopedDataRepository.Get<Request>("Request");
|
||||||
|
|
||||||
if (request.IsError)
|
if (request.IsError)
|
||||||
{
|
{
|
||||||
@ -40,7 +40,7 @@ namespace Ocelot.Requester.Middleware
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_scopedRequestDataRepository.Add("Response", response.Data);
|
_requestScopedDataRepository.Add("Response", response.Data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,8 +1,8 @@
|
|||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Ocelot.Infrastructure.RequestData;
|
||||||
using Ocelot.Middleware;
|
using Ocelot.Middleware;
|
||||||
using Ocelot.ScopedData;
|
|
||||||
|
|
||||||
namespace Ocelot.Responder.Middleware
|
namespace Ocelot.Responder.Middleware
|
||||||
{
|
{
|
||||||
@ -10,18 +10,18 @@ namespace Ocelot.Responder.Middleware
|
|||||||
{
|
{
|
||||||
private readonly RequestDelegate _next;
|
private readonly RequestDelegate _next;
|
||||||
private readonly IHttpResponder _responder;
|
private readonly IHttpResponder _responder;
|
||||||
private readonly IScopedRequestDataRepository _scopedRequestDataRepository;
|
private readonly IRequestScopedDataRepository _requestScopedDataRepository;
|
||||||
private readonly IErrorsToHttpStatusCodeMapper _codeMapper;
|
private readonly IErrorsToHttpStatusCodeMapper _codeMapper;
|
||||||
|
|
||||||
public HttpResponderMiddleware(RequestDelegate next,
|
public HttpResponderMiddleware(RequestDelegate next,
|
||||||
IHttpResponder responder,
|
IHttpResponder responder,
|
||||||
IScopedRequestDataRepository scopedRequestDataRepository,
|
IRequestScopedDataRepository requestScopedDataRepository,
|
||||||
IErrorsToHttpStatusCodeMapper codeMapper)
|
IErrorsToHttpStatusCodeMapper codeMapper)
|
||||||
:base(scopedRequestDataRepository)
|
:base(requestScopedDataRepository)
|
||||||
{
|
{
|
||||||
_next = next;
|
_next = next;
|
||||||
_responder = responder;
|
_responder = responder;
|
||||||
_scopedRequestDataRepository = scopedRequestDataRepository;
|
_requestScopedDataRepository = requestScopedDataRepository;
|
||||||
_codeMapper = codeMapper;
|
_codeMapper = codeMapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,7 +46,7 @@ namespace Ocelot.Responder.Middleware
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var response = _scopedRequestDataRepository.Get<HttpResponseMessage>("Response");
|
var response = _requestScopedDataRepository.Get<HttpResponseMessage>("Response");
|
||||||
|
|
||||||
await _responder.CreateResponse(context, response.Data);
|
await _responder.CreateResponse(context, response.Data);
|
||||||
}
|
}
|
||||||
|
@ -8,8 +8,8 @@ using Microsoft.AspNetCore.Hosting;
|
|||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Ocelot.Configuration.Yaml;
|
using Ocelot.Configuration.Yaml;
|
||||||
|
using Ocelot.Infrastructure.RequestData;
|
||||||
using Ocelot.Middleware;
|
using Ocelot.Middleware;
|
||||||
using Ocelot.ScopedData;
|
|
||||||
using TestStack.BDDfy;
|
using TestStack.BDDfy;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
@ -67,7 +67,7 @@ namespace Ocelot.AcceptanceTests
|
|||||||
{
|
{
|
||||||
PreHttpRequesterMiddleware = async (ctx, next) =>
|
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")});
|
service.Add("Response", new HttpResponseMessage {Content = new StringContent("PreHttpRequesterMiddleware")});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -1,4 +1,26 @@
|
|||||||
ReRoutes:
|
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
|
- DownstreamTemplate: http://www.bbc.co.uk
|
||||||
UpstreamTemplate: /
|
UpstreamTemplate: /
|
||||||
UpstreamHttpMethod: Get
|
UpstreamHttpMethod: Get
|
||||||
|
@ -39,7 +39,8 @@
|
|||||||
"preserveCompilationContext": true,
|
"preserveCompilationContext": true,
|
||||||
"copyToOutput": {
|
"copyToOutput": {
|
||||||
"include": [
|
"include": [
|
||||||
"middlewareConfiguration.yaml"
|
"middlewareConfiguration.yaml",
|
||||||
|
"configuration.yaml"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -57,7 +58,8 @@
|
|||||||
"Areas/**/Views",
|
"Areas/**/Views",
|
||||||
"appsettings.json",
|
"appsettings.json",
|
||||||
"web.config",
|
"web.config",
|
||||||
"middlewareConfiguration.yaml"
|
"middlewareConfiguration.yaml",
|
||||||
|
"configuration.yaml"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -11,8 +11,8 @@ using Ocelot.Authentication.Middleware;
|
|||||||
using Ocelot.Configuration.Builder;
|
using Ocelot.Configuration.Builder;
|
||||||
using Ocelot.DownstreamRouteFinder;
|
using Ocelot.DownstreamRouteFinder;
|
||||||
using Ocelot.DownstreamRouteFinder.UrlMatcher;
|
using Ocelot.DownstreamRouteFinder.UrlMatcher;
|
||||||
|
using Ocelot.Infrastructure.RequestData;
|
||||||
using Ocelot.Responses;
|
using Ocelot.Responses;
|
||||||
using Ocelot.ScopedData;
|
|
||||||
using TestStack.BDDfy;
|
using TestStack.BDDfy;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
@ -20,7 +20,7 @@ namespace Ocelot.UnitTests.Authentication
|
|||||||
{
|
{
|
||||||
public class AuthenticationMiddlewareTests : IDisposable
|
public class AuthenticationMiddlewareTests : IDisposable
|
||||||
{
|
{
|
||||||
private readonly Mock<IScopedRequestDataRepository> _scopedRepository;
|
private readonly Mock<IRequestScopedDataRepository> _scopedRepository;
|
||||||
private readonly Mock<IAuthenticationHandlerFactory> _authFactory;
|
private readonly Mock<IAuthenticationHandlerFactory> _authFactory;
|
||||||
private readonly string _url;
|
private readonly string _url;
|
||||||
private readonly TestServer _server;
|
private readonly TestServer _server;
|
||||||
@ -31,7 +31,7 @@ namespace Ocelot.UnitTests.Authentication
|
|||||||
public AuthenticationMiddlewareTests()
|
public AuthenticationMiddlewareTests()
|
||||||
{
|
{
|
||||||
_url = "http://localhost:51879";
|
_url = "http://localhost:51879";
|
||||||
_scopedRepository = new Mock<IScopedRequestDataRepository>();
|
_scopedRepository = new Mock<IRequestScopedDataRepository>();
|
||||||
_authFactory = new Mock<IAuthenticationHandlerFactory>();
|
_authFactory = new Mock<IAuthenticationHandlerFactory>();
|
||||||
var builder = new WebHostBuilder()
|
var builder = new WebHostBuilder()
|
||||||
.ConfigureServices(x =>
|
.ConfigureServices(x =>
|
||||||
|
@ -11,8 +11,8 @@ using Ocelot.Authorisation;
|
|||||||
using Ocelot.Configuration.Builder;
|
using Ocelot.Configuration.Builder;
|
||||||
using Ocelot.DownstreamRouteFinder;
|
using Ocelot.DownstreamRouteFinder;
|
||||||
using Ocelot.DownstreamRouteFinder.UrlMatcher;
|
using Ocelot.DownstreamRouteFinder.UrlMatcher;
|
||||||
|
using Ocelot.Infrastructure.RequestData;
|
||||||
using Ocelot.Responses;
|
using Ocelot.Responses;
|
||||||
using Ocelot.ScopedData;
|
|
||||||
using TestStack.BDDfy;
|
using TestStack.BDDfy;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
@ -22,7 +22,7 @@ namespace Ocelot.UnitTests.Authorization
|
|||||||
|
|
||||||
public class AuthorisationMiddlewareTests : IDisposable
|
public class AuthorisationMiddlewareTests : IDisposable
|
||||||
{
|
{
|
||||||
private readonly Mock<IScopedRequestDataRepository> _scopedRepository;
|
private readonly Mock<IRequestScopedDataRepository> _scopedRepository;
|
||||||
private readonly Mock<IAuthoriser> _authService;
|
private readonly Mock<IAuthoriser> _authService;
|
||||||
private readonly string _url;
|
private readonly string _url;
|
||||||
private readonly TestServer _server;
|
private readonly TestServer _server;
|
||||||
@ -33,7 +33,7 @@ namespace Ocelot.UnitTests.Authorization
|
|||||||
public AuthorisationMiddlewareTests()
|
public AuthorisationMiddlewareTests()
|
||||||
{
|
{
|
||||||
_url = "http://localhost:51879";
|
_url = "http://localhost:51879";
|
||||||
_scopedRepository = new Mock<IScopedRequestDataRepository>();
|
_scopedRepository = new Mock<IRequestScopedDataRepository>();
|
||||||
_authService = new Mock<IAuthoriser>();
|
_authService = new Mock<IAuthoriser>();
|
||||||
var builder = new WebHostBuilder()
|
var builder = new WebHostBuilder()
|
||||||
.ConfigureServices(x =>
|
.ConfigureServices(x =>
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
namespace Ocelot.UnitTests.ClaimsBuilder
|
using Ocelot.Infrastructure.RequestData;
|
||||||
|
|
||||||
|
namespace Ocelot.UnitTests.ClaimsBuilder
|
||||||
{
|
{
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@ -16,13 +18,12 @@
|
|||||||
using Ocelot.DownstreamRouteFinder;
|
using Ocelot.DownstreamRouteFinder;
|
||||||
using Ocelot.DownstreamRouteFinder.UrlMatcher;
|
using Ocelot.DownstreamRouteFinder.UrlMatcher;
|
||||||
using Responses;
|
using Responses;
|
||||||
using ScopedData;
|
|
||||||
using TestStack.BDDfy;
|
using TestStack.BDDfy;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
public class ClaimsBuilderMiddlewareTests : IDisposable
|
public class ClaimsBuilderMiddlewareTests : IDisposable
|
||||||
{
|
{
|
||||||
private readonly Mock<IScopedRequestDataRepository> _scopedRepository;
|
private readonly Mock<IRequestScopedDataRepository> _scopedRepository;
|
||||||
private readonly Mock<IAddClaimsToRequest> _addHeaders;
|
private readonly Mock<IAddClaimsToRequest> _addHeaders;
|
||||||
private readonly string _url;
|
private readonly string _url;
|
||||||
private readonly TestServer _server;
|
private readonly TestServer _server;
|
||||||
@ -33,7 +34,7 @@
|
|||||||
public ClaimsBuilderMiddlewareTests()
|
public ClaimsBuilderMiddlewareTests()
|
||||||
{
|
{
|
||||||
_url = "http://localhost:51879";
|
_url = "http://localhost:51879";
|
||||||
_scopedRepository = new Mock<IScopedRequestDataRepository>();
|
_scopedRepository = new Mock<IRequestScopedDataRepository>();
|
||||||
_addHeaders = new Mock<IAddClaimsToRequest>();
|
_addHeaders = new Mock<IAddClaimsToRequest>();
|
||||||
var builder = new WebHostBuilder()
|
var builder = new WebHostBuilder()
|
||||||
.ConfigureServices(x =>
|
.ConfigureServices(x =>
|
||||||
|
@ -11,8 +11,8 @@ using Ocelot.DownstreamRouteFinder;
|
|||||||
using Ocelot.DownstreamRouteFinder.Finder;
|
using Ocelot.DownstreamRouteFinder.Finder;
|
||||||
using Ocelot.DownstreamRouteFinder.Middleware;
|
using Ocelot.DownstreamRouteFinder.Middleware;
|
||||||
using Ocelot.DownstreamRouteFinder.UrlMatcher;
|
using Ocelot.DownstreamRouteFinder.UrlMatcher;
|
||||||
|
using Ocelot.Infrastructure.RequestData;
|
||||||
using Ocelot.Responses;
|
using Ocelot.Responses;
|
||||||
using Ocelot.ScopedData;
|
|
||||||
using TestStack.BDDfy;
|
using TestStack.BDDfy;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
@ -21,7 +21,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
|||||||
public class DownstreamRouteFinderMiddlewareTests : IDisposable
|
public class DownstreamRouteFinderMiddlewareTests : IDisposable
|
||||||
{
|
{
|
||||||
private readonly Mock<IDownstreamRouteFinder> _downstreamRouteFinder;
|
private readonly Mock<IDownstreamRouteFinder> _downstreamRouteFinder;
|
||||||
private readonly Mock<IScopedRequestDataRepository> _scopedRepository;
|
private readonly Mock<IRequestScopedDataRepository> _scopedRepository;
|
||||||
private readonly string _url;
|
private readonly string _url;
|
||||||
private readonly TestServer _server;
|
private readonly TestServer _server;
|
||||||
private readonly HttpClient _client;
|
private readonly HttpClient _client;
|
||||||
@ -32,7 +32,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
|||||||
{
|
{
|
||||||
_url = "http://localhost:51879";
|
_url = "http://localhost:51879";
|
||||||
_downstreamRouteFinder = new Mock<IDownstreamRouteFinder>();
|
_downstreamRouteFinder = new Mock<IDownstreamRouteFinder>();
|
||||||
_scopedRepository = new Mock<IScopedRequestDataRepository>();
|
_scopedRepository = new Mock<IRequestScopedDataRepository>();
|
||||||
|
|
||||||
var builder = new WebHostBuilder()
|
var builder = new WebHostBuilder()
|
||||||
.ConfigureServices(x =>
|
.ConfigureServices(x =>
|
||||||
|
@ -11,8 +11,8 @@ using Ocelot.DownstreamRouteFinder;
|
|||||||
using Ocelot.DownstreamRouteFinder.UrlMatcher;
|
using Ocelot.DownstreamRouteFinder.UrlMatcher;
|
||||||
using Ocelot.DownstreamUrlCreator.Middleware;
|
using Ocelot.DownstreamUrlCreator.Middleware;
|
||||||
using Ocelot.DownstreamUrlCreator.UrlTemplateReplacer;
|
using Ocelot.DownstreamUrlCreator.UrlTemplateReplacer;
|
||||||
|
using Ocelot.Infrastructure.RequestData;
|
||||||
using Ocelot.Responses;
|
using Ocelot.Responses;
|
||||||
using Ocelot.ScopedData;
|
|
||||||
using TestStack.BDDfy;
|
using TestStack.BDDfy;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
@ -21,7 +21,7 @@ namespace Ocelot.UnitTests.DownstreamUrlCreator
|
|||||||
public class DownstreamUrlCreatorMiddlewareTests : IDisposable
|
public class DownstreamUrlCreatorMiddlewareTests : IDisposable
|
||||||
{
|
{
|
||||||
private readonly Mock<IDownstreamUrlTemplateVariableReplacer> _downstreamUrlTemplateVariableReplacer;
|
private readonly Mock<IDownstreamUrlTemplateVariableReplacer> _downstreamUrlTemplateVariableReplacer;
|
||||||
private readonly Mock<IScopedRequestDataRepository> _scopedRepository;
|
private readonly Mock<IRequestScopedDataRepository> _scopedRepository;
|
||||||
private readonly string _url;
|
private readonly string _url;
|
||||||
private readonly TestServer _server;
|
private readonly TestServer _server;
|
||||||
private readonly HttpClient _client;
|
private readonly HttpClient _client;
|
||||||
@ -33,7 +33,7 @@ namespace Ocelot.UnitTests.DownstreamUrlCreator
|
|||||||
{
|
{
|
||||||
_url = "http://localhost:51879";
|
_url = "http://localhost:51879";
|
||||||
_downstreamUrlTemplateVariableReplacer = new Mock<IDownstreamUrlTemplateVariableReplacer>();
|
_downstreamUrlTemplateVariableReplacer = new Mock<IDownstreamUrlTemplateVariableReplacer>();
|
||||||
_scopedRepository = new Mock<IScopedRequestDataRepository>();
|
_scopedRepository = new Mock<IRequestScopedDataRepository>();
|
||||||
|
|
||||||
var builder = new WebHostBuilder()
|
var builder = new WebHostBuilder()
|
||||||
.ConfigureServices(x =>
|
.ConfigureServices(x =>
|
||||||
|
@ -13,8 +13,8 @@ using Ocelot.DownstreamRouteFinder;
|
|||||||
using Ocelot.DownstreamRouteFinder.UrlMatcher;
|
using Ocelot.DownstreamRouteFinder.UrlMatcher;
|
||||||
using Ocelot.HeaderBuilder;
|
using Ocelot.HeaderBuilder;
|
||||||
using Ocelot.HeaderBuilder.Middleware;
|
using Ocelot.HeaderBuilder.Middleware;
|
||||||
|
using Ocelot.Infrastructure.RequestData;
|
||||||
using Ocelot.Responses;
|
using Ocelot.Responses;
|
||||||
using Ocelot.ScopedData;
|
|
||||||
using TestStack.BDDfy;
|
using TestStack.BDDfy;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
@ -22,7 +22,7 @@ namespace Ocelot.UnitTests.HeaderBuilder
|
|||||||
{
|
{
|
||||||
public class HttpRequestHeadersBuilderMiddlewareTests : IDisposable
|
public class HttpRequestHeadersBuilderMiddlewareTests : IDisposable
|
||||||
{
|
{
|
||||||
private readonly Mock<IScopedRequestDataRepository> _scopedRepository;
|
private readonly Mock<IRequestScopedDataRepository> _scopedRepository;
|
||||||
private readonly Mock<IAddHeadersToRequest> _addHeaders;
|
private readonly Mock<IAddHeadersToRequest> _addHeaders;
|
||||||
private readonly string _url;
|
private readonly string _url;
|
||||||
private readonly TestServer _server;
|
private readonly TestServer _server;
|
||||||
@ -33,7 +33,7 @@ namespace Ocelot.UnitTests.HeaderBuilder
|
|||||||
public HttpRequestHeadersBuilderMiddlewareTests()
|
public HttpRequestHeadersBuilderMiddlewareTests()
|
||||||
{
|
{
|
||||||
_url = "http://localhost:51879";
|
_url = "http://localhost:51879";
|
||||||
_scopedRepository = new Mock<IScopedRequestDataRepository>();
|
_scopedRepository = new Mock<IRequestScopedDataRepository>();
|
||||||
_addHeaders = new Mock<IAddHeadersToRequest>();
|
_addHeaders = new Mock<IAddHeadersToRequest>();
|
||||||
var builder = new WebHostBuilder()
|
var builder = new WebHostBuilder()
|
||||||
.ConfigureServices(x =>
|
.ConfigureServices(x =>
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Ocelot.Infrastructure.RequestData;
|
||||||
using Ocelot.Responses;
|
using Ocelot.Responses;
|
||||||
using Ocelot.ScopedData;
|
|
||||||
using Shouldly;
|
using Shouldly;
|
||||||
using TestStack.BDDfy;
|
using TestStack.BDDfy;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
@ -9,7 +9,7 @@ namespace Ocelot.UnitTests.Repository
|
|||||||
{
|
{
|
||||||
public class ScopedRequestDataRepositoryTests
|
public class ScopedRequestDataRepositoryTests
|
||||||
{
|
{
|
||||||
private IScopedRequestDataRepository _scopedRequestDataRepository;
|
private IRequestScopedDataRepository _requestScopedDataRepository;
|
||||||
private IHttpContextAccessor _httpContextAccesor;
|
private IHttpContextAccessor _httpContextAccesor;
|
||||||
private string _key;
|
private string _key;
|
||||||
private object _toAdd;
|
private object _toAdd;
|
||||||
@ -19,7 +19,7 @@ namespace Ocelot.UnitTests.Repository
|
|||||||
{
|
{
|
||||||
_httpContextAccesor = new HttpContextAccessor();
|
_httpContextAccesor = new HttpContextAccessor();
|
||||||
_httpContextAccesor.HttpContext = new DefaultHttpContext();
|
_httpContextAccesor.HttpContext = new DefaultHttpContext();
|
||||||
_scopedRequestDataRepository = new ScopedRequestDataRepository(_httpContextAccesor);
|
_requestScopedDataRepository = new HttpDataRepository(_httpContextAccesor);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@ -48,7 +48,7 @@ namespace Ocelot.UnitTests.Repository
|
|||||||
|
|
||||||
private void WhenIGetTheItem()
|
private void WhenIGetTheItem()
|
||||||
{
|
{
|
||||||
_result = _scopedRequestDataRepository.Get<int[]>(_key);
|
_result = _requestScopedDataRepository.Get<int[]>(_key);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void GivenThereIsAnItemInTheContext(string key)
|
private void GivenThereIsAnItemInTheContext(string key)
|
||||||
@ -66,7 +66,7 @@ namespace Ocelot.UnitTests.Repository
|
|||||||
|
|
||||||
private void WhenIAddTheItem()
|
private void WhenIAddTheItem()
|
||||||
{
|
{
|
||||||
_scopedRequestDataRepository.Add(_key, _toAdd);
|
_requestScopedDataRepository.Add(_key, _toAdd);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ThenTheItemIsAdded()
|
private void ThenTheItemIsAdded()
|
||||||
|
@ -7,11 +7,11 @@ using Microsoft.AspNetCore.Http;
|
|||||||
using Microsoft.AspNetCore.TestHost;
|
using Microsoft.AspNetCore.TestHost;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Moq;
|
using Moq;
|
||||||
|
using Ocelot.Infrastructure.RequestData;
|
||||||
using Ocelot.RequestBuilder;
|
using Ocelot.RequestBuilder;
|
||||||
using Ocelot.RequestBuilder.Builder;
|
using Ocelot.RequestBuilder.Builder;
|
||||||
using Ocelot.RequestBuilder.Middleware;
|
using Ocelot.RequestBuilder.Middleware;
|
||||||
using Ocelot.Responses;
|
using Ocelot.Responses;
|
||||||
using Ocelot.ScopedData;
|
|
||||||
using TestStack.BDDfy;
|
using TestStack.BDDfy;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
@ -20,7 +20,7 @@ namespace Ocelot.UnitTests.RequestBuilder
|
|||||||
public class HttpRequestBuilderMiddlewareTests : IDisposable
|
public class HttpRequestBuilderMiddlewareTests : IDisposable
|
||||||
{
|
{
|
||||||
private readonly Mock<IRequestBuilder> _requestBuilder;
|
private readonly Mock<IRequestBuilder> _requestBuilder;
|
||||||
private readonly Mock<IScopedRequestDataRepository> _scopedRepository;
|
private readonly Mock<IRequestScopedDataRepository> _scopedRepository;
|
||||||
private readonly string _url;
|
private readonly string _url;
|
||||||
private readonly TestServer _server;
|
private readonly TestServer _server;
|
||||||
private readonly HttpClient _client;
|
private readonly HttpClient _client;
|
||||||
@ -32,7 +32,7 @@ namespace Ocelot.UnitTests.RequestBuilder
|
|||||||
{
|
{
|
||||||
_url = "http://localhost:51879";
|
_url = "http://localhost:51879";
|
||||||
_requestBuilder = new Mock<IRequestBuilder>();
|
_requestBuilder = new Mock<IRequestBuilder>();
|
||||||
_scopedRepository = new Mock<IScopedRequestDataRepository>();
|
_scopedRepository = new Mock<IRequestScopedDataRepository>();
|
||||||
|
|
||||||
var builder = new WebHostBuilder()
|
var builder = new WebHostBuilder()
|
||||||
.ConfigureServices(x =>
|
.ConfigureServices(x =>
|
||||||
|
@ -6,11 +6,11 @@ using Microsoft.AspNetCore.Hosting;
|
|||||||
using Microsoft.AspNetCore.TestHost;
|
using Microsoft.AspNetCore.TestHost;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Moq;
|
using Moq;
|
||||||
|
using Ocelot.Infrastructure.RequestData;
|
||||||
using Ocelot.RequestBuilder;
|
using Ocelot.RequestBuilder;
|
||||||
using Ocelot.Requester;
|
using Ocelot.Requester;
|
||||||
using Ocelot.Requester.Middleware;
|
using Ocelot.Requester.Middleware;
|
||||||
using Ocelot.Responses;
|
using Ocelot.Responses;
|
||||||
using Ocelot.ScopedData;
|
|
||||||
using TestStack.BDDfy;
|
using TestStack.BDDfy;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
@ -19,7 +19,7 @@ namespace Ocelot.UnitTests.Requester
|
|||||||
public class HttpRequesterMiddlewareTests : IDisposable
|
public class HttpRequesterMiddlewareTests : IDisposable
|
||||||
{
|
{
|
||||||
private readonly Mock<IHttpRequester> _requester;
|
private readonly Mock<IHttpRequester> _requester;
|
||||||
private readonly Mock<IScopedRequestDataRepository> _scopedRepository;
|
private readonly Mock<IRequestScopedDataRepository> _scopedRepository;
|
||||||
private readonly string _url;
|
private readonly string _url;
|
||||||
private readonly TestServer _server;
|
private readonly TestServer _server;
|
||||||
private readonly HttpClient _client;
|
private readonly HttpClient _client;
|
||||||
@ -31,7 +31,7 @@ namespace Ocelot.UnitTests.Requester
|
|||||||
{
|
{
|
||||||
_url = "http://localhost:51879";
|
_url = "http://localhost:51879";
|
||||||
_requester = new Mock<IHttpRequester>();
|
_requester = new Mock<IHttpRequester>();
|
||||||
_scopedRepository = new Mock<IScopedRequestDataRepository>();
|
_scopedRepository = new Mock<IRequestScopedDataRepository>();
|
||||||
|
|
||||||
var builder = new WebHostBuilder()
|
var builder = new WebHostBuilder()
|
||||||
.ConfigureServices(x =>
|
.ConfigureServices(x =>
|
||||||
|
@ -6,10 +6,10 @@ using Microsoft.AspNetCore.Http;
|
|||||||
using Microsoft.AspNetCore.TestHost;
|
using Microsoft.AspNetCore.TestHost;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Moq;
|
using Moq;
|
||||||
|
using Ocelot.Infrastructure.RequestData;
|
||||||
using Ocelot.Responder;
|
using Ocelot.Responder;
|
||||||
using Ocelot.Responder.Middleware;
|
using Ocelot.Responder.Middleware;
|
||||||
using Ocelot.Responses;
|
using Ocelot.Responses;
|
||||||
using Ocelot.ScopedData;
|
|
||||||
using TestStack.BDDfy;
|
using TestStack.BDDfy;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
@ -18,7 +18,7 @@ namespace Ocelot.UnitTests.Responder
|
|||||||
public class HttpResponderMiddlewareTests : IDisposable
|
public class HttpResponderMiddlewareTests : IDisposable
|
||||||
{
|
{
|
||||||
private readonly Mock<IHttpResponder> _responder;
|
private readonly Mock<IHttpResponder> _responder;
|
||||||
private readonly Mock<IScopedRequestDataRepository> _scopedRepository;
|
private readonly Mock<IRequestScopedDataRepository> _scopedRepository;
|
||||||
private readonly Mock<IErrorsToHttpStatusCodeMapper> _codeMapper;
|
private readonly Mock<IErrorsToHttpStatusCodeMapper> _codeMapper;
|
||||||
private readonly string _url;
|
private readonly string _url;
|
||||||
private readonly TestServer _server;
|
private readonly TestServer _server;
|
||||||
@ -30,7 +30,7 @@ namespace Ocelot.UnitTests.Responder
|
|||||||
{
|
{
|
||||||
_url = "http://localhost:51879";
|
_url = "http://localhost:51879";
|
||||||
_responder = new Mock<IHttpResponder>();
|
_responder = new Mock<IHttpResponder>();
|
||||||
_scopedRepository = new Mock<IScopedRequestDataRepository>();
|
_scopedRepository = new Mock<IRequestScopedDataRepository>();
|
||||||
_codeMapper = new Mock<IErrorsToHttpStatusCodeMapper>();
|
_codeMapper = new Mock<IErrorsToHttpStatusCodeMapper>();
|
||||||
|
|
||||||
var builder = new WebHostBuilder()
|
var builder = new WebHostBuilder()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user