diff options
| author | Bond-009 <bond.009@outlook.com> | 2020-07-22 18:41:58 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-07-22 18:41:58 +0200 |
| commit | 89ff865d408686dc592e613f51628027537dc6d4 (patch) | |
| tree | 03e924a34ce106a72279d160c36cfcd3ea1e545a | |
| parent | a86d8d1757e92284166bfd2fe3c1a564f3307b13 (diff) | |
| parent | 301ddc1dacb1f7a8c67c62e1ebeeb9badc478bb8 (diff) | |
Merge pull request #3508 from BaronGreenback/nullable
Part 1: nullable Emby.DLNA
4 files changed, 41 insertions, 4 deletions
diff --git a/Emby.Dlna/Api/DlnaServerService.cs b/Emby.Dlna/Api/DlnaServerService.cs index 7fba2184a..d9c1669b0 100644 --- a/Emby.Dlna/Api/DlnaServerService.cs +++ b/Emby.Dlna/Api/DlnaServerService.cs @@ -11,6 +11,7 @@ using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Dlna; using MediaBrowser.Controller.Net; using MediaBrowser.Model.Services; +using Microsoft.AspNetCore.Http; namespace Emby.Dlna.Api { @@ -108,7 +109,7 @@ namespace Emby.Dlna.Api public string Filename { get; set; } } - public class DlnaServerService : IService, IRequiresRequest + public class DlnaServerService : IService { private const string XMLContentType = "text/xml; charset=UTF-8"; @@ -127,11 +128,13 @@ namespace Emby.Dlna.Api public DlnaServerService( IDlnaManager dlnaManager, IHttpResultFactory httpResultFactory, - IServerConfigurationManager configurationManager) + IServerConfigurationManager configurationManager, + IHttpContextAccessor httpContextAccessor) { _dlnaManager = dlnaManager; _resultFactory = httpResultFactory; _configurationManager = configurationManager; + Request = httpContextAccessor?.HttpContext.GetServiceStackRequest() ?? throw new ArgumentNullException(nameof(httpContextAccessor)); } private string GetHeader(string name) diff --git a/Emby.Server.Implementations/Services/ServiceController.cs b/Emby.Server.Implementations/Services/ServiceController.cs index 857df591a..d884d4f37 100644 --- a/Emby.Server.Implementations/Services/ServiceController.cs +++ b/Emby.Server.Implementations/Services/ServiceController.cs @@ -189,5 +189,4 @@ namespace Emby.Server.Implementations.Services return ServiceExecGeneral.Execute(serviceType, req, service, requestDto, requestType.GetMethodName()); } } - } diff --git a/Emby.Server.Implementations/Services/ServiceHandler.cs b/Emby.Server.Implementations/Services/ServiceHandler.cs index a42f88ea0..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; @@ -78,7 +79,8 @@ namespace Emby.Server.Implementations.Services var request = await CreateRequest(httpHost, httpReq, _restPath, logger).ConfigureAwait(false); httpHost.ApplyRequestFilters(httpReq, httpRes, request); - + + httpRes.HttpContext.SetServiceStackRequest(httpReq); var response = await httpHost.ServiceController.Execute(httpHost, request, httpReq).ConfigureAwait(false); // Apply response filters diff --git a/MediaBrowser.Common/Extensions/HttpContextExtensions.cs b/MediaBrowser.Common/Extensions/HttpContextExtensions.cs new file mode 100644 index 000000000..d746207c7 --- /dev/null +++ b/MediaBrowser.Common/Extensions/HttpContextExtensions.cs @@ -0,0 +1,33 @@ +using MediaBrowser.Model.Services; +using Microsoft.AspNetCore.Http; + +namespace MediaBrowser.Common.Extensions +{ + /// <summary> + /// Static class containing extension methods for <see cref="HttpContext"/>. + /// </summary> + public static class HttpContextExtensions + { + private const string ServiceStackRequest = "ServiceStackRequest"; + + /// <summary> + /// Set the ServiceStack request. + /// </summary> + /// <param name="httpContext">The HttpContext instance.</param> + /// <param name="request">The service stack request instance.</param> + public static void SetServiceStackRequest(this HttpContext httpContext, IRequest request) + { + httpContext.Items[ServiceStackRequest] = request; + } + + /// <summary> + /// Get the ServiceStack request. + /// </summary> + /// <param name="httpContext">The HttpContext instance.</param> + /// <returns>The service stack request instance.</returns> + public static IRequest GetServiceStackRequest(this HttpContext httpContext) + { + return (IRequest)httpContext.Items[ServiceStackRequest]; + } + } +} |
