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
42 changes: 24 additions & 18 deletions src/Caching/StackExchangeRedis/src/RedisCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -323,29 +323,35 @@ private void TryRegisterProfiler()

// This also resets the LRU status as desired.
// TODO: Can this be done in one operation on the server side? Probably, the trick would just be the DateTimeOffset math.
RedisValue[] results;
if (getData)
{
results = _cache.HashMemberGet(_instance + key, AbsoluteExpirationKey, SlidingExpirationKey, DataKey);
}
else
try
{
results = _cache.HashMemberGet(_instance + key, AbsoluteExpirationKey, SlidingExpirationKey);
}
RedisValue[] results;
if (getData)
{
results = _cache.HashMemberGet(_instance + key, AbsoluteExpirationKey, SlidingExpirationKey, DataKey);
}
else
{
results = _cache.HashMemberGet(_instance + key, AbsoluteExpirationKey, SlidingExpirationKey);
}

// TODO: Error handling
if (results.Length >= 2)
{
MapMetadata(results, out DateTimeOffset? absExpr, out TimeSpan? sldExpr);
Refresh(_cache, key, absExpr, sldExpr);
}
if (results.Length >= 2)
{
MapMetadata(results, out DateTimeOffset? absExpr, out TimeSpan? sldExpr);
Refresh(_cache, key, absExpr, sldExpr);
}

if (results.Length >= 3 && results[2].HasValue)
if (results.Length >= 3 && results[2].HasValue)
{
return results[2];
}

return null;
}
catch (RedisConnectionException ex)
{
return results[2];
throw new InvalidOperationException("Redis cache connection failed. See inner exception for details.", ex);
}

return null;
}

private async Task<byte[]?> GetAndRefreshAsync(string key, bool getData, CancellationToken token = default(CancellationToken))
Expand Down
7 changes: 5 additions & 2 deletions src/Http/WebUtilities/src/FormReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Buffers;
using System.Diagnostics.CodeAnalysis;
using System.Text;
using Microsoft.AspNetCore.Internal;
using Microsoft.Extensions.Primitives;

namespace Microsoft.AspNetCore.WebUtilities;
Expand Down Expand Up @@ -264,10 +265,12 @@ private bool ReadChar(char separator, int limit, [NotNullWhen(true)] out string?
// '+' un-escapes to ' ', %HH un-escapes as ASCII (or utf-8?)
private string BuildWord()
{
_builder.Replace('+', ' ');
var result = _builder.ToString();
_builder.Clear();
return Uri.UnescapeDataString(result); // TODO: Replace this, it's not completely accurate.

var bytes = Encoding.UTF8.GetBytes(result);
var decodedLength = UrlDecoder.DecodeInPlace(bytes, isFormEncoding: true);
return Encoding.UTF8.GetString(bytes, 0, decodedLength);
}

private void Buffer()
Expand Down
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