Skip to content

Commit 6ff053e

Browse files
committed
Added a new Middleware to add info to ResponseHeader
1 parent b07caf6 commit 6ff053e

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using Microsoft.AspNetCore.Builder;
2+
using Microsoft.AspNetCore.Http;
3+
using System.Threading.Tasks;
4+
5+
namespace Practices.Middlewares
6+
{
7+
8+
public static class DeveloperInfoMiddlewareExtensions
9+
{
10+
public static IApplicationBuilder UseDeveloperInfoMiddleware(this IApplicationBuilder builder)
11+
{
12+
return builder.UseMiddleware<DeveloperInfoMiddleware>();
13+
}
14+
}
15+
16+
public class DeveloperInfoMiddleware
17+
{
18+
private readonly RequestDelegate _next;
19+
20+
public DeveloperInfoMiddleware(RequestDelegate next)
21+
{
22+
_next = next;
23+
}
24+
25+
public async Task InvokeAsync(HttpContext context)
26+
{
27+
context.Response.Headers.Add("x-Developed-By","Gsoster");
28+
await _next(context);
29+
}
30+
31+
}
32+
}

ASP.NETPractices/Practices/Startup.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,13 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env)
5858
});
5959

6060

61+
62+
6163

6264
//app.UseMiddleware<RequestTimeLoggerMiddleware>(); //since I added an extension method now I can just call:
6365
app.UseRequestTimeLoggerMiddleware();
6466

67+
app.UseDeveloperInfoMiddleware();
6568

6669
/* //Playing with Middlewares
6770
app.Use(async (context, next)=>{

0 commit comments

Comments
 (0)