Skip to content
Closed
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
2 changes: 1 addition & 1 deletion src/Middleware/RateLimiting/src/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ Microsoft.AspNetCore.RateLimiting.RateLimiterOptions.OnRejected.set -> void
Microsoft.AspNetCore.RateLimiting.RateLimiterOptions.RateLimiterOptions() -> void
Microsoft.AspNetCore.RateLimiting.RateLimitingApplicationBuilderExtensions
static Microsoft.AspNetCore.RateLimiting.RateLimitingApplicationBuilderExtensions.UseRateLimiter(this Microsoft.AspNetCore.Builder.IApplicationBuilder! app) -> Microsoft.AspNetCore.Builder.IApplicationBuilder!
static Microsoft.AspNetCore.RateLimiting.RateLimitingApplicationBuilderExtensions.UseRateLimiter(this Microsoft.AspNetCore.Builder.IApplicationBuilder! app, Microsoft.AspNetCore.RateLimiting.RateLimiterOptions! options) -> Microsoft.AspNetCore.Builder.IApplicationBuilder!
static Microsoft.AspNetCore.RateLimiting.RateLimitingApplicationBuilderExtensions.UseRateLimiter(this Microsoft.AspNetCore.Builder.IApplicationBuilder! app, System.Action<Microsoft.AspNetCore.RateLimiting.RateLimiterOptions!>! options) -> Microsoft.AspNetCore.Builder.IApplicationBuilder!
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,14 @@ public static IApplicationBuilder UseRateLimiter(this IApplicationBuilder app)
/// <param name="app"></param>
/// <param name="options"></param>
/// <returns></returns>
public static IApplicationBuilder UseRateLimiter(this IApplicationBuilder app, RateLimiterOptions options)
public static IApplicationBuilder UseRateLimiter(this IApplicationBuilder app, Action<RateLimiterOptions> options)
{
ArgumentNullException.ThrowIfNull(app, nameof(app));
ArgumentNullException.ThrowIfNull(options, nameof(options));

return app.UseMiddleware<RateLimitingMiddleware>(Options.Create(options));
var rateLimiterOptions = new RateLimiterOptions();
options.Invoke(rateLimiterOptions);

return app.UseMiddleware<RateLimitingMiddleware>(Options.Create(rateLimiterOptions));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ public void UseRateLimiter_ThrowsOnNullOptions()
public void UseRateLimiter_RespectsOptions()
{
// These are the options that should get used
var options = new RateLimiterOptions();
options.DefaultRejectionStatusCode = 429;
options.Limiter = new TestPartitionedRateLimiter<HttpContext>(new TestRateLimiter(false));
var configureOptions = new Action<RateLimiterOptions>(opt =>
{
opt.DefaultRejectionStatusCode = 429;
opt.Limiter = new TestPartitionedRateLimiter<HttpContext>(new TestRateLimiter(false));
});

// These should not get used
var services = new ServiceCollection();
Expand All @@ -44,7 +46,7 @@ public void UseRateLimiter_RespectsOptions()
var appBuilder = new ApplicationBuilder(serviceProvider);

// Act
appBuilder.UseRateLimiter(options);
appBuilder.UseRateLimiter(configureOptions);
var app = appBuilder.Build();
var context = new DefaultHttpContext();
app.Invoke(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public AddCommand(Application parent, IHttpClientWrapper httpClient)
: base(parent, CommandName, httpClient)
{
Commands.Add(new AddFileCommand(this, httpClient));
//TODO: Add AddprojectComand here: https://github.com/dotnet/aspnetcore/issues/12738
Commands.Add(new AddProjectCommand(this, httpClient));
Commands.Add(new AddURLCommand(this, httpClient));
}

Expand Down
Loading