Radarr/src/Radarr.Http/Middleware/VersionMiddleware.cs

32 lines
854 B
C#
Raw Normal View History

2021-10-21 20:04:19 +00:00
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using NzbDrone.Common.EnvironmentInfo;
using Radarr.Http.Extensions;
2021-10-21 20:04:19 +00:00
namespace Radarr.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))
2021-10-21 20:04:19 +00:00
{
2023-11-17 02:43:18 +00:00
context.Response.Headers.Append(VERSIONHEADER, _version);
2021-10-21 20:04:19 +00:00
}
await _next(context);
}
}
}