diff --git a/1.1.png b/1.1.png new file mode 100644 index 0000000..8cf3dd1 Binary files /dev/null and b/1.1.png differ diff --git a/TaskHub/Api/Api.csproj b/TaskHub/Api/Api.csproj index a6946fa..7405f43 100644 --- a/TaskHub/Api/Api.csproj +++ b/TaskHub/Api/Api.csproj @@ -1,7 +1,7 @@ - net10.0 + net8.0 enable enable @@ -12,7 +12,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/TaskHub/Api/Middleware/ResponseTimeMiddleware.cs.cs b/TaskHub/Api/Middleware/ResponseTimeMiddleware.cs.cs new file mode 100644 index 0000000..1f1b9d1 --- /dev/null +++ b/TaskHub/Api/Middleware/ResponseTimeMiddleware.cs.cs @@ -0,0 +1,28 @@ +using System.Diagnostics; + +namespace Api.Middleware +{ + public class ResponseTimeMiddleware + { + private readonly RequestDelegate _next; + + public ResponseTimeMiddleware(RequestDelegate next) + { + _next = next; + } + + public async Task InvokeAsync(HttpContext context) + { + var stopwatch = Stopwatch.StartNew(); + + context.Response.OnStarting(() => + { + stopwatch.Stop(); + context.Response.Headers["X-Response-Time-Ms"] = stopwatch.ElapsedMilliseconds.ToString(); + return Task.CompletedTask; + }); + + await _next(context); + } + } +} diff --git a/TaskHub/Api/Middleware/StudentInfoMiddleware.cs b/TaskHub/Api/Middleware/StudentInfoMiddleware.cs new file mode 100644 index 0000000..23db0ab --- /dev/null +++ b/TaskHub/Api/Middleware/StudentInfoMiddleware.cs @@ -0,0 +1,24 @@ +namespace Api.Middleware +{ + public class StudentInfoMiddleware + { + private readonly RequestDelegate _next; + + public StudentInfoMiddleware(RequestDelegate next) + { + _next = next; + } + + public async Task InvokeAsync(HttpContext context) + { + context.Response.OnStarting(() => + { + context.Response.Headers["X-Student-Name"] = "Tumashova Marina"; + context.Response.Headers["X-Student-Group"] = "RI-240912"; + return Task.CompletedTask; + }); + + await _next(context); + } + } +} diff --git a/TaskHub/Api/StartUp.cs b/TaskHub/Api/StartUp.cs index 9220ca4..1d6c0a2 100644 --- a/TaskHub/Api/StartUp.cs +++ b/TaskHub/Api/StartUp.cs @@ -1,3 +1,4 @@ +using Api.Middleware; using Api.UseCases.Users; using Api.UseCases.Users.Interfaces; using Dal; @@ -81,6 +82,9 @@ public void Configure(IApplicationBuilder app) app.UseRouting(); + app.UseMiddleware(); + app.UseMiddleware(); + app.UseEndpoints(endpoints => { endpoints.MapControllers(); diff --git a/TaskHub/Dal/Dal.csproj b/TaskHub/Dal/Dal.csproj index edb5ba8..1c690cf 100644 --- a/TaskHub/Dal/Dal.csproj +++ b/TaskHub/Dal/Dal.csproj @@ -1,14 +1,14 @@  - net10.0 + net8.0 enable enable - - + + diff --git a/TaskHub/Libs/DatabaseLibrary/DatabaseLibrary.csproj b/TaskHub/Libs/DatabaseLibrary/DatabaseLibrary.csproj index 0c323c8..012f0c1 100644 --- a/TaskHub/Libs/DatabaseLibrary/DatabaseLibrary.csproj +++ b/TaskHub/Libs/DatabaseLibrary/DatabaseLibrary.csproj @@ -1,14 +1,14 @@  - net10.0 + net8.0 enable enable - - + + diff --git a/TaskHub/Libs/LoggingLibrary/LoggingLibrary.csproj b/TaskHub/Libs/LoggingLibrary/LoggingLibrary.csproj index bf06657..ff7786d 100644 --- a/TaskHub/Libs/LoggingLibrary/LoggingLibrary.csproj +++ b/TaskHub/Libs/LoggingLibrary/LoggingLibrary.csproj @@ -1,15 +1,15 @@  - net10.0 + net8.0 enable enable - + - + diff --git a/TaskHub/Logic/Logic.csproj b/TaskHub/Logic/Logic.csproj index a38dfe4..2be5253 100644 --- a/TaskHub/Logic/Logic.csproj +++ b/TaskHub/Logic/Logic.csproj @@ -5,11 +5,11 @@ - + - net10.0 + net8.0 enable enable