Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose the original status code in StatusCodeReExecuteFeature #46539

Merged
merged 5 commits into from
Mar 4, 2023
Merged
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 @@ -28,6 +28,11 @@ public interface IStatusCodeReExecuteFeature
/// </summary>
string? OriginalQueryString { get; set; }

/// <summary>
/// The <see cref="HttpResponse.StatusCode"/> of the original response.
/// </summary>
int OriginalStatusCode => throw new NotImplementedException();

/// <summary>
/// Gets the selected <see cref="Http.Endpoint"/> for the original request.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#nullable enable
Microsoft.AspNetCore.Diagnostics.IStatusCodeReExecuteFeature.OriginalStatusCode.get -> int
1 change: 1 addition & 0 deletions src/Middleware/Diagnostics/src/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#nullable enable
Microsoft.AspNetCore.Diagnostics.StatusCodeReExecuteFeature.OriginalStatusCode.get -> int
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,12 @@ private static Func<StatusCodeContext, Task> CreateHandler(string pathFormat, st
{
var handler = async (StatusCodeContext context) =>
{
var originalStatusCode = context.HttpContext.Response.StatusCode;

var newPath = new PathString(
string.Format(CultureInfo.InvariantCulture, pathFormat, context.HttpContext.Response.StatusCode));
string.Format(CultureInfo.InvariantCulture, pathFormat, originalStatusCode));
var formatedQueryString = queryFormat == null ? null :
string.Format(CultureInfo.InvariantCulture, queryFormat, context.HttpContext.Response.StatusCode);
string.Format(CultureInfo.InvariantCulture, queryFormat, originalStatusCode);
var newQueryString = queryFormat == null ? QueryString.Empty : new QueryString(formatedQueryString);

var originalPath = context.HttpContext.Request.Path;
Expand All @@ -181,6 +183,7 @@ private static Func<StatusCodeContext, Task> CreateHandler(string pathFormat, st
OriginalPathBase = context.HttpContext.Request.PathBase.Value!,
OriginalPath = originalPath.Value!,
OriginalQueryString = originalQueryString.HasValue ? originalQueryString.Value : null,
OriginalStatusCode = originalStatusCode,
Endpoint = context.HttpContext.GetEndpoint(),
RouteValues = routeValuesFeature?.RouteValues
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ public class StatusCodeReExecuteFeature : IStatusCodeReExecuteFeature
/// <inheritdoc/>
public string? OriginalQueryString { get; set; }

/// <inheritdoc/>
public int OriginalStatusCode { get; internal set; }

/// <inheritdoc/>
public Endpoint? Endpoint { get; set; }

Expand Down