Skip to content

Commit a87ee42

Browse files
committed
Add missing CustomHeaderAttribute
1 parent aee9041 commit a87ee42

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace Initium.Attributes;
2+
3+
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true)]
4+
public class CustomHeaderAttribute(string headerName, string headerValue) : Attribute
5+
{
6+
public string HeaderName { get; } = headerName;
7+
public string HeaderValue { get; } = headerValue;
8+
}

src/Initium/Controllers/ApiController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace Initium.Controllers;
1515
[TypeFilter(typeof(ApiResponseFilter))]
1616
[TypeFilter(typeof(LoggingFilter))]
1717
[TypeFilter(typeof(ImplicitValidationFilter))]
18-
[TypeFilter(typeof(CustomHeaderFilter))]
18+
// [TypeFilter(typeof(CustomHeaderFilter))]
1919
public abstract class ApiController : BaseController;
2020

2121
/// <summary>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using Initium.Attributes;
2+
using Microsoft.AspNetCore.Mvc.Filters;
3+
4+
namespace Initium.Filters;
5+
6+
internal class CustomHeaderFilter : IActionFilter
7+
{
8+
public void OnActionExecuting(ActionExecutingContext context)
9+
{
10+
}
11+
12+
public void OnActionExecuted(ActionExecutedContext context) =>
13+
context.ActionDescriptor.EndpointMetadata
14+
.OfType<CustomHeaderAttribute>()
15+
.ToList()
16+
.ForEach(customHeader => context.HttpContext.Response.Headers[customHeader.HeaderName] = customHeader.HeaderValue);
17+
}

0 commit comments

Comments
 (0)