File tree Expand file tree Collapse file tree 3 files changed +26
-1
lines changed
Expand file tree Collapse file tree 3 files changed +26
-1
lines changed Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff 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))]
1919public abstract class ApiController : BaseController ;
2020
2121/// <summary>
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments