diff --git a/src/Ocelot/Claims/Middleware/ClaimsBuilderMiddlewareExtensions.cs b/src/Ocelot/Claims/Middleware/ClaimsBuilderMiddlewareExtensions.cs index a1d929ec..2751d23a 100644 --- a/src/Ocelot/Claims/Middleware/ClaimsBuilderMiddlewareExtensions.cs +++ b/src/Ocelot/Claims/Middleware/ClaimsBuilderMiddlewareExtensions.cs @@ -1,9 +1,8 @@ -using Microsoft.AspNetCore.Builder; -using Ocelot.Middleware.Pipeline; +using Ocelot.Middleware.Pipeline; namespace Ocelot.Claims.Middleware { - public static class ClaimsToClaimsMiddlewareExtensions + public static class ClaimsBuilderMiddlewareExtensions { public static IOcelotPipelineBuilder UseClaimsToClaimsMiddleware(this IOcelotPipelineBuilder builder) { diff --git a/src/Ocelot/Configuration/Creator/LoadBalancerOptionsCreator.cs b/src/Ocelot/Configuration/Creator/LoadBalancerOptionsCreator.cs index c7770c24..af2c22c1 100644 --- a/src/Ocelot/Configuration/Creator/LoadBalancerOptionsCreator.cs +++ b/src/Ocelot/Configuration/Creator/LoadBalancerOptionsCreator.cs @@ -2,7 +2,6 @@ using Ocelot.Configuration.File; namespace Ocelot.Configuration.Creator { - public class LoadBalancerOptionsCreator : ILoadBalancerOptionsCreator { public LoadBalancerOptions Create(FileLoadBalancerOptions options) diff --git a/src/Ocelot/Infrastructure/Placeholders.cs b/src/Ocelot/Infrastructure/Placeholders.cs index 325499e5..4069eb26 100644 --- a/src/Ocelot/Infrastructure/Placeholders.cs +++ b/src/Ocelot/Infrastructure/Placeholders.cs @@ -26,7 +26,6 @@ namespace Ocelot.Infrastructure { "{BaseUrl}", GetBaseUrl() }, { "{TraceId}", GetTraceId() }, { "{RemoteIpAddress}", GetRemoteIpAddress() } - }; _requestPlaceholders = new Dictionary> @@ -37,10 +36,10 @@ namespace Ocelot.Infrastructure public Response Get(string key) { - if(_placeholders.ContainsKey(key)) + if (_placeholders.ContainsKey(key)) { var response = _placeholders[key].Invoke(); - if(!response.IsError) + if (!response.IsError) { return new OkResponse(response.Data); } @@ -51,7 +50,7 @@ namespace Ocelot.Infrastructure public Response Get(string key, DownstreamRequest request) { - if(_requestPlaceholders.ContainsKey(key)) + if (_requestPlaceholders.ContainsKey(key)) { return new OkResponse(_requestPlaceholders[key].Invoke(request)); } @@ -61,22 +60,22 @@ namespace Ocelot.Infrastructure public Response Add(string key, Func> func) { - if(_placeholders.ContainsKey(key)) + if (_placeholders.ContainsKey(key)) { return new ErrorResponse(new CannotAddPlaceholderError($"Unable to add placeholder: {key}, placeholder already exists")); } - + _placeholders.Add(key, func); return new OkResponse(); } public Response Remove(string key) { - if(!_placeholders.ContainsKey(key)) + if (!_placeholders.ContainsKey(key)) { return new ErrorResponse(new CannotRemovePlaceholderError($"Unable to remove placeholder: {key}, placeholder does not exists")); } - + _placeholders.Remove(key); return new OkResponse(); } @@ -91,7 +90,7 @@ namespace Ocelot.Infrastructure var remoteIdAddress = _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString(); return new OkResponse(remoteIdAddress); } - catch (Exception e) + catch { return new ErrorResponse(new CouldNotFindPlaceholderError("{RemoteIpAddress}")); } diff --git a/src/Ocelot/LoadBalancer/LoadBalancers/LoadBalancerHouse.cs b/src/Ocelot/LoadBalancer/LoadBalancers/LoadBalancerHouse.cs index 6d195d4d..8f7e8135 100644 --- a/src/Ocelot/LoadBalancer/LoadBalancers/LoadBalancerHouse.cs +++ b/src/Ocelot/LoadBalancer/LoadBalancers/LoadBalancerHouse.cs @@ -1,9 +1,9 @@ -using System; +using Ocelot.Configuration; +using Ocelot.Responses; +using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Threading.Tasks; -using Ocelot.Configuration; -using Ocelot.Responses; namespace Ocelot.LoadBalancer.LoadBalancers { @@ -35,6 +35,7 @@ namespace Ocelot.LoadBalancer.LoadBalancers { return new ErrorResponse(result.Errors); } + loadBalancer = result.Data; AddLoadBalancer(reRoute.LoadBalancerKey, loadBalancer); } @@ -43,10 +44,12 @@ namespace Ocelot.LoadBalancer.LoadBalancers } result = await _factory.Get(reRoute, config); + if (result.IsError) { return new ErrorResponse(result.Errors); } + loadBalancer = result.Data; AddLoadBalancer(reRoute.LoadBalancerKey, loadBalancer); return new OkResponse(loadBalancer); diff --git a/src/Ocelot/Logging/OcelotDiagnosticListener.cs b/src/Ocelot/Logging/OcelotDiagnosticListener.cs index 48c1a35c..8a5c0215 100644 --- a/src/Ocelot/Logging/OcelotDiagnosticListener.cs +++ b/src/Ocelot/Logging/OcelotDiagnosticListener.cs @@ -15,7 +15,6 @@ namespace Ocelot.Logging { _logger = factory.CreateLogger(); _tracer = serviceProvider.GetService(); - } [DiagnosticName("Ocelot.MiddlewareException")] @@ -60,7 +59,7 @@ namespace Ocelot.Logging } private void Event(HttpContext httpContext, string @event) - { + { _tracer?.Event(httpContext, @event); } } diff --git a/src/Ocelot/Middleware/OcelotMiddlewareExtensions.cs b/src/Ocelot/Middleware/OcelotMiddlewareExtensions.cs index 14877d4f..78d32346 100644 --- a/src/Ocelot/Middleware/OcelotMiddlewareExtensions.cs +++ b/src/Ocelot/Middleware/OcelotMiddlewareExtensions.cs @@ -76,6 +76,7 @@ // now create the config var internalConfigCreator = builder.ApplicationServices.GetService(); var internalConfig = await internalConfigCreator.Create(fileConfig.CurrentValue); + //Configuration error, throw error message if (internalConfig.IsError) { @@ -102,9 +103,9 @@ await configuration(builder); } - if(AdministrationApiInUse(adminPath)) + if (AdministrationApiInUse(adminPath)) { - //We have to make sure the file config is set for the ocelot.env.json and ocelot.json so that if we pull it from the + //We have to make sure the file config is set for the ocelot.env.json and ocelot.json so that if we pull it from the //admin api it works...boy this is getting a spit spags boll. var fileConfigSetter = builder.ApplicationServices.GetService(); diff --git a/src/Ocelot/Middleware/OcelotPipelineConfiguration.cs b/src/Ocelot/Middleware/OcelotPipelineConfiguration.cs index c7f6e231..3dbb76a7 100644 --- a/src/Ocelot/Middleware/OcelotPipelineConfiguration.cs +++ b/src/Ocelot/Middleware/OcelotPipelineConfiguration.cs @@ -8,7 +8,7 @@ public class OcelotPipelineConfiguration { /// - /// This is called after the global error handling middleware so any code before calling next.invoke + /// This is called after the global error handling middleware so any code before calling next.invoke /// is the next thing called in the Ocelot pipeline. Anything after next.invoke is the last thing called /// in the Ocelot pipeline before we go to the global error handler. /// @@ -40,6 +40,7 @@ /// This allows the user to implement there own query string manipulation logic /// public Func, Task> PreQueryStringBuilderMiddleware { get; set; } + /// /// This is an extension that will branch to different pipes /// diff --git a/src/Ocelot/Middleware/Pipeline/OcelotPipelineBuilderExtensions.cs b/src/Ocelot/Middleware/Pipeline/OcelotPipelineBuilderExtensions.cs index bc558533..2c0b14ed 100644 --- a/src/Ocelot/Middleware/Pipeline/OcelotPipelineBuilderExtensions.cs +++ b/src/Ocelot/Middleware/Pipeline/OcelotPipelineBuilderExtensions.cs @@ -2,14 +2,13 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Removed code and changed RequestDelete to OcelotRequestDelete, HttpContext to DownstreamContext, removed some exception handling messages +using Microsoft.Extensions.DependencyInjection; using System; using System.Diagnostics; using System.Linq; using System.Linq.Expressions; using System.Reflection; using System.Threading.Tasks; -using Microsoft.AspNetCore.Http; -using Microsoft.Extensions.DependencyInjection; namespace Ocelot.Middleware.Pipeline { @@ -167,10 +166,12 @@ namespace Ocelot.Middleware.Pipeline { throw new ArgumentNullException(nameof(app)); } + if (pipelineBuilderFunc == null) { throw new ArgumentNullException(nameof(pipelineBuilderFunc)); } + var branchBuilder = app.New(); var predicate = pipelineBuilderFunc.Invoke(branchBuilder); var branch = branchBuilder.Build(); diff --git a/src/Ocelot/Requester/OcelotHttpTracingHandler.cs b/src/Ocelot/Requester/OcelotHttpTracingHandler.cs index b5585d57..0ad4d410 100644 --- a/src/Ocelot/Requester/OcelotHttpTracingHandler.cs +++ b/src/Ocelot/Requester/OcelotHttpTracingHandler.cs @@ -13,7 +13,7 @@ private readonly IRequestScopedDataRepository _repo; public OcelotHttpTracingHandler( - ITracer tracer, + ITracer tracer, IRequestScopedDataRepository repo, HttpMessageHandler httpMessageHandler = null) { @@ -23,11 +23,10 @@ } protected override Task SendAsync( - HttpRequestMessage request, + HttpRequestMessage request, CancellationToken cancellationToken) { - - return _tracer.SendAsync(request, cancellationToken, x => _repo.Add("TraceId", x), (r,c) => base.SendAsync(r, c)); + return _tracer.SendAsync(request, cancellationToken, x => _repo.Add("TraceId", x), (r, c) => base.SendAsync(r, c)); } } }