mirror of
https://github.com/Prowlarr/Prowlarr.git
synced 2025-12-23 22:28:00 -05:00
32 lines
852 B
C#
32 lines
852 B
C#
using System.Threading.Tasks;
|
|
using Microsoft.AspNetCore.Http;
|
|
using NzbDrone.Common.EnvironmentInfo;
|
|
using Prowlarr.Http.Extensions;
|
|
|
|
namespace Prowlarr.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[VERSIONHEADER] = _version;
|
|
}
|
|
|
|
await _next(context);
|
|
}
|
|
}
|
|
}
|