Skip to content

Commit 4088520

Browse files
feat(compare): enable local compare targets by default in Development
1 parent 26073d2 commit 4088520

5 files changed

Lines changed: 11 additions & 5 deletions

File tree

DebugProbe.AspNetCore.Tests/Configuration/DebugProbeOptionsTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public void Defaults_work_correctly()
1414

1515
Assert.Equal(20, options.MaxEntries);
1616
Assert.Equal(32, options.MaxBodyCaptureSizeKb);
17-
Assert.False(options.AllowLocalCompareTargets);
17+
Assert.Null(options.AllowLocalCompareTargets);
1818
Assert.Empty(options.IgnorePaths);
1919
}
2020

DebugProbe.AspNetCore/Extensions/DebugProbeExtensions.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using Microsoft.AspNetCore.Builder;
1212
using Microsoft.AspNetCore.Http;
1313
using Microsoft.Extensions.DependencyInjection;
14+
using Microsoft.Extensions.Hosting;
1415
using Microsoft.Extensions.Http;
1516

1617
namespace DebugProbe.AspNetCore.Extensions;
@@ -60,6 +61,11 @@ public static IServiceCollection AddDebugProbe(this IServiceCollection services,
6061
/// </summary>
6162
public static IApplicationBuilder UseDebugProbe(this IApplicationBuilder app)
6263
{
64+
var options = app.ApplicationServices.GetRequiredService<DebugProbeOptions>();
65+
var environment = app.ApplicationServices.GetRequiredService<IHostEnvironment>();
66+
67+
options.AllowLocalCompareTargets ??= environment.IsDevelopment();
68+
6369
app.UseMiddleware<DebugProbeMiddleware>();
6470
app.ApplicationServices.GetRequiredService<DebugEntryStore>();
6571

DebugProbe.AspNetCore/Internal/Compare/CompareUrlValidator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ internal static class CompareUrlValidator
3434
return (false, null, "Failed to resolve compare server host");
3535
}
3636

37-
if (!options.AllowLocalCompareTargets)
37+
if (options.AllowLocalCompareTargets != true)
3838
{
3939
if (IsLocalHostName(parsed.Host))
4040
{

DebugProbe.AspNetCore/Options/DebugProbeOptions.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ public class DebugProbeOptions
1818
internal int MaxBodyCaptureSizeBytes => MaxBodyCaptureSizeKb * 1024;
1919

2020
/// <summary>
21-
/// Allows compare requests to local or private network targets.
21+
/// Allows compare operations to target localhost and private network addresses.
22+
/// Defaults to true in Development and false in other environments unless explicitly configured.
2223
/// </summary>
23-
public bool AllowLocalCompareTargets { get; set; }
24+
public bool? AllowLocalCompareTargets { get; set; }
2425

2526
/// <summary>
2627
/// Additional request paths to ignore.

DebugProbe.SampleApi/Program.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
builder.Services.AddDebugProbe(options =>
1212
{
1313
options.MaxEntries = 10;
14-
options.AllowLocalCompareTargets = true;
1514
});
1615

1716
var app = builder.Build();

0 commit comments

Comments
 (0)