Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ protected virtual HttpHandlerOptions Merge(FileHttpHandlerOptions options, FileH
options.UseCookieContainer ??= globalOptions.UseCookieContainer ?? false;
options.UseProxy ??= globalOptions.UseProxy ?? false;
options.UseTracing ??= globalOptions.UseTracing ?? false;
options.UseDefaultCredentials ??= globalOptions.UseDefaultCredentials ?? false;
var useTracing = _tracer != null && options.UseTracing.Value;
return new(options, useTracing);
}
Expand Down
6 changes: 4 additions & 2 deletions src/Ocelot/Configuration/File/FileHttpHandlerOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ public FileHttpHandlerOptions(FileHttpHandlerOptions from)
UseCookieContainer = from.UseCookieContainer;
UseProxy = from.UseProxy;
UseTracing = from.UseTracing;
UseDefaultCredentials = from.UseDefaultCredentials;
}

public bool? AllowAutoRedirect { get; set; }
public int? MaxConnectionsPerServer { get; set; }
public int? PooledConnectionLifetimeSeconds { get; set; }
public bool? UseCookieContainer { get; set; }
public bool? UseProxy { get; set; }
public bool? UseTracing { get; set; }
}
public bool? UseTracing { get; set; }
public bool? UseDefaultCredentials { get; set; }
}
15 changes: 14 additions & 1 deletion src/Ocelot/Configuration/HttpHandlerOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public HttpHandlerOptions(FileHttpHandlerOptions from)
UseCookieContainer = from.UseCookieContainer ?? false;
UseProxy = from.UseProxy ?? false;
UseTracing = from.UseTracing ?? false;
UseDefaultCredentials = from.UseDefaultCredentials ?? false;
}

public HttpHandlerOptions(FileHttpHandlerOptions from, bool useTracing)
Expand Down Expand Up @@ -59,12 +60,24 @@ public HttpHandlerOptions(FileHttpHandlerOptions from, bool useTracing)
/// <summary>
/// Specify the maximum of concurrent connection to a network endpoint.
/// </summary>
/// <value>MaxConnectionsPerServer.</value>
/// <value>
/// The maximum number of concurrent connections (per server endpoint) allowed by an <see cref="HttpClient"/> object.
/// The property value is assignable to the <see cref="HttpClientHandler.MaxConnectionsPerServer"/> one.
/// </value>
public int MaxConnectionsPerServer { get; init; }

/// <summary>
/// Specify the maximum of time a connection can be pooled.
/// </summary>
/// <value>PooledConnectionLifeTime.</value>
public TimeSpan PooledConnectionLifeTime { get; init; }

/// <summary>
/// Specify is UseDefaultCredentials set on HttpClientHandler.
/// </summary>
/// <value>
/// <see langword="true"/> if the default credentials are used; otherwise <see langword="false"/>. The default value is <see langword="false"/>.
/// The property value is assignable to the <see cref="HttpClientHandler.UseDefaultCredentials"/> one.
/// </value>
public bool UseDefaultCredentials { get; init; }
}
1 change: 1 addition & 0 deletions src/Ocelot/Requester/MessageInvokerPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ protected virtual SocketsHttpHandler CreateHandler(DownstreamRoute route)
UseProxy = options.UseProxy,
MaxConnectionsPerServer = options.MaxConnectionsPerServer,
PooledConnectionLifetime = options.PooledConnectionLifeTime,
Credentials = options.UseDefaultCredentials ? CredentialCache.DefaultCredentials : null,
};

if (options.UseCookieContainer)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection;
using Ocelot.Configuration;
using Ocelot.Configuration.Creator;
using Ocelot.Configuration.File;
using Ocelot.Configuration.File;
using Ocelot.Logging;
using System.Reflection;

Expand Down Expand Up @@ -324,6 +324,37 @@ public void Merge(bool isDef, bool hasTracer)
Assert.Equal(!isDef, actual.UseProxy);
Assert.Equal(hasTracer && !isDef, actual.UseTracing); // the useTracing parameter takes absolute priority
}

[Fact]
[Trait("Feat", "657")]
public void Should_create_options_with_useDefaultCredentials_false_as_default()
{
// Arrange
FileHttpHandlerOptions opts = new();

// Act
var actual = _creator.Create(opts);

// Assert
Assert.False(actual.UseDefaultCredentials);
}

[Fact]
[Trait("Feat", "657")]
public void Should_create_options_with_UseDefaultCredentials_true_if_set()
{
// Arrange
FileHttpHandlerOptions opts = new()
{
UseDefaultCredentials = true,
};

// Act
var actual = _creator.Create(opts);

// Assert
Assert.True(actual.UseDefaultCredentials);
}

private static FileHttpHandlerOptions RouteOptions() => new()
{
Expand Down
Loading