Lidarr/src/Lidarr.Http/Middleware/VersionMiddleware.cs
Mark McDowall bfb3c632d7 New: Only add version header for API requests
(cherry picked from commit 453891e620459ff38f7bc43b207004b240fc5fb8)
2023-05-07 13:53:53 +03:00

31 lines
851 B
C#

using System.Threading.Tasks;
using Lidarr.Http.Extensions;
using Microsoft.AspNetCore.Http;
using NzbDrone.Common.EnvironmentInfo;
namespace Lidarr.Http.Middleware
{
public class VersionMiddleware
{
private const string VERSIONHEADER = "X-Application-Version";
private readonly RequestDelegate _next;
private readonly string _version;
public VersionMiddleware(RequestDelegate next)
{
_next = next;
_version = BuildInfo.Version.ToString();
}
public async Task InvokeAsync(HttpContext context)
{
if (context.Request.IsApiRequest() && !context.Response.Headers.ContainsKey(VERSIONHEADER))
{
context.Response.Headers.Add(VERSIONHEADER, _version);
}
await _next(context);
}
}
}