From 3ff3452e2d1dea1845f1fd41ae98b74f3f6b02ec Mon Sep 17 00:00:00 2001 From: Qstick Date: Thu, 8 Dec 2022 17:50:18 -0600 Subject: [PATCH] Handling for Obsolete API Endpoints --- src/Prowlarr.Http/REST/RestController.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/Prowlarr.Http/REST/RestController.cs b/src/Prowlarr.Http/REST/RestController.cs index 6475d4b43..3c2bbd527 100644 --- a/src/Prowlarr.Http/REST/RestController.cs +++ b/src/Prowlarr.Http/REST/RestController.cs @@ -6,6 +6,8 @@ using FluentValidation.Results; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Controllers; using Microsoft.AspNetCore.Mvc.Filters; +using NLog; +using NzbDrone.Common.Instrumentation; using NzbDrone.Core.Datastore; using NzbDrone.Http.REST.Attributes; using Prowlarr.Http.Validation; @@ -16,7 +18,9 @@ namespace Prowlarr.Http.REST where TResource : RestResource, new() { private static readonly List VALIDATE_ID_ATTRIBUTES = new List { typeof(RestPutByIdAttribute), typeof(RestDeleteByIdAttribute) }; + private static readonly Type DEPRECATED_ATTRIBUTE = typeof(ObsoleteAttribute); + private readonly Logger _logger; protected ResourceValidator PostValidator { get; private set; } protected ResourceValidator PutValidator { get; private set; } protected ResourceValidator SharedValidator { get; private set; } @@ -31,6 +35,8 @@ namespace Prowlarr.Http.REST protected RestController() { + _logger = NzbDroneLogger.GetLogger(this); + PostValidator = new ResourceValidator(); PutValidator = new ResourceValidator(); SharedValidator = new ResourceValidator(); @@ -76,6 +82,13 @@ namespace Prowlarr.Http.REST } } + var controllerAttributes = descriptor.ControllerTypeInfo.CustomAttributes; + if (controllerAttributes.Any(x => x.AttributeType == DEPRECATED_ATTRIBUTE) || attributes.Any(x => x.AttributeType == DEPRECATED_ATTRIBUTE)) + { + _logger.Warn("API call made to deprecated endpoint from {0}", Request.Headers.UserAgent.ToString()); + Response.Headers.Add("Deprecation", "true"); + } + base.OnActionExecuting(context); }