Skip to content

Commit

Permalink
Fix Remarks
Browse files Browse the repository at this point in the history
  • Loading branch information
hogwartsdeveloper committed May 28, 2024
1 parent 2993d4c commit 5c18640
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
5 changes: 1 addition & 4 deletions src/Ocelot/DependencyInjection/OcelotBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,7 @@ public OcelotBuilder(IServiceCollection services, IConfiguration configurationRo
Configuration = configurationRoot;
Services = services;
Services.Configure<FileConfiguration>(configurationRoot);
Services.TryAddSingleton(
sp => sp
.GetRequiredService<IOptions<FileConfiguration>>()
.Value.GlobalConfiguration);
Services.Configure<FileGlobalConfiguration>(configurationRoot.GetSection("GlobalConfiguration"));

Services.TryAddSingleton<IHttpResponseHeaderReplacer, HttpResponseHeaderReplacer>();
Services.TryAddSingleton<IHttpContextRequestHeaderReplacer, HttpContextRequestHeaderReplacer>();
Expand Down
13 changes: 8 additions & 5 deletions src/Ocelot/Requester/MessageInvokerPool.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Ocelot.Configuration;
using Microsoft.Extensions.Options;
using Ocelot.Configuration;
using Ocelot.Configuration.File;
using Ocelot.Logging;
using System.Net.Security;
Expand All @@ -10,19 +11,21 @@ public class MessageInvokerPool : IMessageInvokerPool
private readonly ConcurrentDictionary<MessageInvokerCacheKey, Lazy<HttpMessageInvoker>> _handlersPool;
private readonly IDelegatingHandlerHandlerFactory _handlerFactory;
private readonly IOcelotLogger _logger;
private readonly FileGlobalConfiguration _global;

public MessageInvokerPool(
IDelegatingHandlerHandlerFactory handlerFactory,
IOcelotLoggerFactory loggerFactory,
FileGlobalConfiguration fileGlobalConfigure)
IOptions<FileGlobalConfiguration> global)
{
_handlerFactory = handlerFactory ?? throw new ArgumentNullException(nameof(handlerFactory));
_handlersPool = new ConcurrentDictionary<MessageInvokerCacheKey, Lazy<HttpMessageInvoker>>();

ArgumentNullException.ThrowIfNull(loggerFactory);
_logger = loggerFactory.CreateLogger<MessageInvokerPool>();

RequestTimeoutSeconds = fileGlobalConfigure.RequestTimeoutSeconds ?? 0;
_global = global.Value;
_requestTimeoutSeconds = _global.RequestTimeoutSeconds;
}

public HttpMessageInvoker Get(DownstreamRoute downstreamRoute)
Expand All @@ -40,11 +43,11 @@ public HttpMessageInvoker Get(DownstreamRoute downstreamRoute)

public const int DefaultRequestTimeoutSeconds = 90;

private int _requestTimeoutSeconds;
private int? _requestTimeoutSeconds;

public int RequestTimeoutSeconds
{
get => _requestTimeoutSeconds > 0 ? _requestTimeoutSeconds : DefaultRequestTimeoutSeconds;
get => _requestTimeoutSeconds ?? _global?.RequestTimeoutSeconds ?? DefaultRequestTimeoutSeconds;
set => _requestTimeoutSeconds = value > 0 ? value : DefaultRequestTimeoutSeconds;
}

Expand Down

0 comments on commit 5c18640

Please sign in to comment.