Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
.
  • Loading branch information
jamescrosswell committed Jul 3, 2025
commit 2ef850d98ec40cc29979a639fdbf8c52d3c93ed9
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using Microsoft.AspNetCore.RequestDecompression;
using Microsoft.Extensions.Logging;

namespace Sentry.AspNetCore.Internal.RequestDecompression;
namespace Sentry.AspNetCore.RequestDecompression;

/// <summary>
/// Enables HTTP request decompression.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// Adapted from: https://github.com/dotnet/aspnetcore/blob/c18e93a9a2e2949e1a9c880da16abf0837aa978f/src/Shared/SizeLimitedStream.cs
// Copied from: https://github.com/dotnet/aspnetcore/blob/c18e93a9a2e2949e1a9c880da16abf0837aa978f/src/Shared/SizeLimitedStream.cs
// The only changes are the namespace and the addition of this comment

// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace Sentry.AspNetCore.Internal.RequestDecompression;
namespace Sentry.AspNetCore.RequestDecompression;

#nullable enable

Expand Down
8 changes: 3 additions & 5 deletions src/Sentry.AspNetCore/SentryStartupFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Microsoft.AspNetCore.RequestDecompression;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Sentry.AspNetCore.RequestDecompression;
using Sentry.Extensibility;

namespace Sentry.AspNetCore;
Expand All @@ -18,15 +19,12 @@ public class SentryStartupFilter : IStartupFilter
public Action<IApplicationBuilder> Configure(Action<IApplicationBuilder> next) => app =>
{
// If we are capturing request bodies and the user has configured request body decompression, we need to
// ensure that the RequestDecompression middleware gets called before Sentry's middleware. The last middleware
// added is the first one to be executed.
// ensure that the RequestDecompression middleware gets called before Sentry's middleware.
var options = app.ApplicationServices.GetService<IOptions<SentryAspNetCoreOptions>>();
if (options?.Value is { } o && o.MaxRequestBodySize != RequestSize.None
&& app.ApplicationServices.GetService<IRequestDecompressionProvider>() is not null)
{
// We've vendored in a custom implementation of RequestDecompressionMiddleware to ensure we can capture
// any exceptions that might occur during decompression.
app.UseMiddleware<Internal.RequestDecompression.RequestDecompressionMiddleware>();
app.UseMiddleware<RequestDecompressionMiddleware>();
}

app.UseSentry();
Expand Down
Loading