From f9b0816b80793965ef044f6871a7ffd80e91d303 Mon Sep 17 00:00:00 2001 From: BaronGreenback Date: Sat, 18 Jul 2020 16:54:23 +0100 Subject: Changes a suggested. --- Emby.Dlna/Api/DlnaServerService.cs | 3 +- .../Services/HttpContextExtension.cs | 33 --------------------- .../Services/ServiceHandler.cs | 1 + .../Extensions/HttpContextExtensions.cs | 34 ++++++++++++++++++++++ 4 files changed, 36 insertions(+), 35 deletions(-) delete mode 100644 Emby.Server.Implementations/Services/HttpContextExtension.cs create mode 100644 MediaBrowser.Common/Extensions/HttpContextExtensions.cs diff --git a/Emby.Dlna/Api/DlnaServerService.cs b/Emby.Dlna/Api/DlnaServerService.cs index 7e5eb8f90..a61a8d5ab 100644 --- a/Emby.Dlna/Api/DlnaServerService.cs +++ b/Emby.Dlna/Api/DlnaServerService.cs @@ -134,8 +134,7 @@ namespace Emby.Dlna.Api _dlnaManager = dlnaManager; _resultFactory = httpResultFactory; _configurationManager = configurationManager; - object request = httpContextAccessor?.HttpContext.Items["ServiceStackRequest"] ?? throw new ArgumentNullException(nameof(httpContextAccessor)); - Request = (IRequest)request; + Request = httpContextAccessor?.HttpContext.GetServiceStack() ?? throw new ArgumentNullException(nameof(httpContextAccessor)); } private string GetHeader(string name) diff --git a/Emby.Server.Implementations/Services/HttpContextExtension.cs b/Emby.Server.Implementations/Services/HttpContextExtension.cs deleted file mode 100644 index 6d3a600ab..000000000 --- a/Emby.Server.Implementations/Services/HttpContextExtension.cs +++ /dev/null @@ -1,33 +0,0 @@ -using MediaBrowser.Model.Services; -using Microsoft.AspNetCore.Http; - -namespace Emby.Server.Implementations.Services -{ - /// - /// Extention to enable the service stack request to be stored in the HttpRequest object. - /// - public static class HttpContextExtension - { - private const string SERVICESTACKREQUEST = "ServiceRequestStack"; - - /// - /// Set the service stack request. - /// - /// The HttpContext instance. - /// The IRequest instance. - public static void SetServiceStackRequest(this HttpContext httpContext, IRequest request) - { - httpContext.Items[SERVICESTACKREQUEST] = request; - } - - /// - /// Get the service stack request. - /// - /// The HttpContext instance. - /// The service stack request instance. - public static IRequest GetServiceStack(this HttpContext httpContext) - { - return (IRequest)httpContext.Items[SERVICESTACKREQUEST]; - } - } -} diff --git a/Emby.Server.Implementations/Services/ServiceHandler.cs b/Emby.Server.Implementations/Services/ServiceHandler.cs index 3997a5ddb..3d4e1ca77 100644 --- a/Emby.Server.Implementations/Services/ServiceHandler.cs +++ b/Emby.Server.Implementations/Services/ServiceHandler.cs @@ -6,6 +6,7 @@ using System.Reflection; using System.Threading; using System.Threading.Tasks; using Emby.Server.Implementations.HttpServer; +using MediaBrowser.Common.Extensions; using MediaBrowser.Model.Services; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Logging; diff --git a/MediaBrowser.Common/Extensions/HttpContextExtensions.cs b/MediaBrowser.Common/Extensions/HttpContextExtensions.cs new file mode 100644 index 000000000..4bab42cc1 --- /dev/null +++ b/MediaBrowser.Common/Extensions/HttpContextExtensions.cs @@ -0,0 +1,34 @@ +using MediaBrowser.Model.Services; +using Microsoft.AspNetCore.Http; + +namespace MediaBrowser.Common.Extensions +{ + /// + /// Extention to enable the service stack request to be stored in the HttpRequest object. + /// Static class containing extension methods for . + /// + public static class HttpContextExtensions + { + private const string SERVICESTACKREQUEST = "ServiceStackRequest"; + + /// + /// Set the ServiceStack request. + /// + /// The HttpContext instance. + /// The service stack request instance. + public static void SetServiceStackRequest(this HttpContext httpContext, IRequest request) + { + httpContext.Items[SERVICESTACKREQUEST] = request; + } + + /// + /// Get the ServiceStack request. + /// + /// The HttpContext instance. + /// The service stack request instance. + public static IRequest GetServiceStack(this HttpContext httpContext) + { + return (IRequest)httpContext.Items[SERVICESTACKREQUEST]; + } + } +} -- cgit v1.2.3