2021-10-21 20:04:19 +00:00
|
|
|
using System.Threading.Tasks;
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
using NzbDrone.Common.EnvironmentInfo;
|
2023-05-07 05:34:22 +00:00
|
|
|
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)
|
|
|
|
{
|
2023-05-07 05:34:22 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|