mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-06-19 12:58:16 +08:00
added benchmarks back in, renamed data repository and a few other things
This commit is contained in:
@ -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;
|
||||
}
|
||||
@ -45,6 +45,6 @@ namespace Ocelot.ScopedData
|
||||
{
|
||||
new CannotFindDataError($"Unable to find data for key: {key}")
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user