From 0f23c7cfc1372ead03ab9b818e698441d4d53bd3 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Wed, 30 Aug 2017 14:52:29 -0400 Subject: 3.2.30.3 --- .../HttpServer/HttpListenerHost.cs | 67 +++++++++++----------- 1 file changed, 33 insertions(+), 34 deletions(-) (limited to 'Emby.Server.Implementations/HttpServer/HttpListenerHost.cs') diff --git a/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs b/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs index f1fea2085..9297362f9 100644 --- a/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs +++ b/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs @@ -10,7 +10,6 @@ using System.Reflection; using System.Text; using System.Threading; using System.Threading.Tasks; -using Emby.Server.Implementations.HttpServer; using Emby.Server.Implementations.HttpServer.SocketSharp; using Emby.Server.Implementations.Services; using MediaBrowser.Common.Net; @@ -34,7 +33,7 @@ namespace Emby.Server.Implementations.HttpServer private string DefaultRedirectPath { get; set; } private readonly ILogger _logger; - public IEnumerable UrlPrefixes { get; private set; } + public string[] UrlPrefixes { get; private set; } private readonly List _restServices = new List(); @@ -62,8 +61,8 @@ namespace Emby.Server.Implementations.HttpServer private readonly Func> _funcParseFn; private readonly bool _enableDualModeSockets; - public List> RequestFilters { get; set; } - public List> ResponseFilters { get; set; } + public Action[] RequestFilters { get; set; } + public Action[] ResponseFilters { get; set; } private readonly Dictionary ServiceOperationsMap = new Dictionary(); public static HttpListenerHost Instance { get; protected set; } @@ -95,8 +94,8 @@ namespace Emby.Server.Implementations.HttpServer _logger = logger; - RequestFilters = new List>(); - ResponseFilters = new List>(); + RequestFilters = new Action[] { }; + ResponseFilters = new Action[] { }; } public string GlobalResponse { get; set; } @@ -135,7 +134,9 @@ namespace Emby.Server.Implementations.HttpServer //Exec all RequestFilter attributes with Priority < 0 var attributes = GetRequestFilterAttributes(requestDto.GetType()); var i = 0; - for (; i < attributes.Length && attributes[i].Priority < 0; i++) + var count = attributes.Count; + + for (; i < count && attributes[i].Priority < 0; i++) { var attribute = attributes[i]; attribute.RequestFilter(req, res, requestDto); @@ -148,7 +149,7 @@ namespace Emby.Server.Implementations.HttpServer } //Exec remaining RequestFilter attributes with Priority >= 0 - for (; i < attributes.Length && attributes[i].Priority >= 0; i++) + for (; i < count && attributes[i].Priority >= 0; i++) { var attribute = attributes[i]; attribute.RequestFilter(req, res, requestDto); @@ -167,7 +168,7 @@ namespace Emby.Server.Implementations.HttpServer ServiceOperationsMap[requestType] = serviceType; } - private IHasRequestFilter[] GetRequestFilterAttributes(Type requestDtoType) + private List GetRequestFilterAttributes(Type requestDtoType) { var attributes = requestDtoType.GetTypeInfo().GetCustomAttributes(true).OfType().ToList(); @@ -179,24 +180,7 @@ namespace Emby.Server.Implementations.HttpServer attributes.Sort((x, y) => x.Priority - y.Priority); - return attributes.ToArray(attributes.Count); - } - - /// - /// Starts the Web Service - /// - private void StartListener() - { - WebSocketSharpRequest.HandlerFactoryPath = GetHandlerPathIfAny(UrlPrefixes.First()); - - _listener = GetListener(); - - _listener.WebSocketConnected = OnWebSocketConnected; - _listener.WebSocketConnecting = OnWebSocketConnecting; - _listener.ErrorHandler = ErrorHandler; - _listener.RequestHandler = RequestHandler; - - _listener.Start(UrlPrefixes); + return attributes; } public static string GetHandlerPathIfAny(string listenerUrl) @@ -698,13 +682,18 @@ namespace Emby.Server.Implementations.HttpServer ServiceController.Init(this, types); - var requestFilters = _appHost.GetExports().ToList(); - foreach (var filter in requestFilters) + var list = new List>(); + foreach (var filter in _appHost.GetExports()) { - RequestFilters.Add(filter.Filter); + list.Add(filter.Filter); } - ResponseFilters.Add(new ResponseFilter(_logger).FilterResponse); + RequestFilters = list.ToArray(); + + ResponseFilters = new Action[] + { + new ResponseFilter(_logger).FilterResponse + }; } public RouteAttribute[] GetRouteAttributes(Type requestType) @@ -819,10 +808,20 @@ namespace Emby.Server.Implementations.HttpServer GC.SuppressFinalize(this); } - public void StartServer(IEnumerable urlPrefixes) + public void StartServer(string[] urlPrefixes) { - UrlPrefixes = urlPrefixes.ToList(); - StartListener(); + UrlPrefixes = urlPrefixes; + + WebSocketSharpRequest.HandlerFactoryPath = GetHandlerPathIfAny(UrlPrefixes[0]); + + _listener = GetListener(); + + _listener.WebSocketConnected = OnWebSocketConnected; + _listener.WebSocketConnecting = OnWebSocketConnecting; + _listener.ErrorHandler = ErrorHandler; + _listener.RequestHandler = RequestHandler; + + _listener.Start(UrlPrefixes); } } } \ No newline at end of file -- cgit v1.2.3