-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f54ffa5
commit 14f48fe
Showing
18 changed files
with
293 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/// <summary> | ||
/// Forbidden object result. | ||
/// </summary> | ||
public class ForbiddenObjectResult : IResult | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="ForbiddenObjectResult"/> class. | ||
/// </summary> | ||
/// <param name="value">Value.</param> | ||
/// <param name="contentType">Content type.</param> | ||
public ForbiddenObjectResult(object value, string contentType) => | ||
(ContentType, Value) = (contentType, value); | ||
|
||
/// <summary> | ||
/// Gets the value for the <c>Content-Type</c> header. | ||
/// </summary> | ||
public string ContentType { get; } | ||
|
||
/// <summary> | ||
/// The object result. | ||
/// </summary> | ||
public object Value { get; } | ||
|
||
/// <inheritdoc/> | ||
public Task ExecuteAsync(HttpContext httpContext) | ||
{ | ||
int forbiddenStatusCode = StatusCodes.Status403Forbidden; | ||
|
||
Type valueType = Value.GetType(); | ||
|
||
LogForbiddenObjectResultExecuting(httpContext, valueType); | ||
|
||
httpContext.Response.StatusCode = forbiddenStatusCode; | ||
|
||
return httpContext.Response.WriteAsJsonAsync( | ||
Value, valueType, options: null, contentType: ContentType); | ||
} | ||
|
||
private void LogForbiddenObjectResultExecuting(HttpContext httpContext, Type valueType) | ||
{ | ||
ILoggerFactory? loggerFactory = httpContext | ||
.RequestServices | ||
.GetRequiredService<ILoggerFactory>(); | ||
|
||
ILogger? logger = loggerFactory.CreateLogger(GetType()); | ||
|
||
logger?.LogInformation( | ||
"Executing {ResultName}. Writing value of type {ValueTypeName}.", | ||
nameof(ForbiddenObjectResult), | ||
valueType.Name); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.