mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-03-02 00:12:24 +00:00
3.2.30.3
This commit is contained in:
@@ -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<string> UrlPrefixes { get; private set; }
|
||||
public string[] UrlPrefixes { get; private set; }
|
||||
|
||||
private readonly List<IService> _restServices = new List<IService>();
|
||||
|
||||
@@ -62,8 +61,8 @@ namespace Emby.Server.Implementations.HttpServer
|
||||
private readonly Func<Type, Func<string, object>> _funcParseFn;
|
||||
private readonly bool _enableDualModeSockets;
|
||||
|
||||
public List<Action<IRequest, IResponse, object>> RequestFilters { get; set; }
|
||||
public List<Action<IRequest, IResponse, object>> ResponseFilters { get; set; }
|
||||
public Action<IRequest, IResponse, object>[] RequestFilters { get; set; }
|
||||
public Action<IRequest, IResponse, object>[] ResponseFilters { get; set; }
|
||||
|
||||
private readonly Dictionary<Type, Type> ServiceOperationsMap = new Dictionary<Type, Type>();
|
||||
public static HttpListenerHost Instance { get; protected set; }
|
||||
@@ -95,8 +94,8 @@ namespace Emby.Server.Implementations.HttpServer
|
||||
|
||||
_logger = logger;
|
||||
|
||||
RequestFilters = new List<Action<IRequest, IResponse, object>>();
|
||||
ResponseFilters = new List<Action<IRequest, IResponse, object>>();
|
||||
RequestFilters = new Action<IRequest, IResponse, object>[] { };
|
||||
ResponseFilters = new Action<IRequest, IResponse, object>[] { };
|
||||
}
|
||||
|
||||
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<IHasRequestFilter> GetRequestFilterAttributes(Type requestDtoType)
|
||||
{
|
||||
var attributes = requestDtoType.GetTypeInfo().GetCustomAttributes(true).OfType<IHasRequestFilter>().ToList();
|
||||
|
||||
@@ -179,24 +180,7 @@ namespace Emby.Server.Implementations.HttpServer
|
||||
|
||||
attributes.Sort((x, y) => x.Priority - y.Priority);
|
||||
|
||||
return attributes.ToArray(attributes.Count);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Starts the Web Service
|
||||
/// </summary>
|
||||
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<IRequestFilter>().ToList();
|
||||
foreach (var filter in requestFilters)
|
||||
var list = new List<Action<IRequest, IResponse, object>>();
|
||||
foreach (var filter in _appHost.GetExports<IRequestFilter>())
|
||||
{
|
||||
RequestFilters.Add(filter.Filter);
|
||||
list.Add(filter.Filter);
|
||||
}
|
||||
|
||||
ResponseFilters.Add(new ResponseFilter(_logger).FilterResponse);
|
||||
RequestFilters = list.ToArray();
|
||||
|
||||
ResponseFilters = new Action<IRequest, IResponse, object>[]
|
||||
{
|
||||
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<string> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,8 @@
|
||||
using MediaBrowser.Model.Logging;
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using MediaBrowser.Model.Services;
|
||||
using SocketHttpListener.Net;
|
||||
using MediaBrowser.Model.Extensions;
|
||||
|
||||
namespace Emby.Server.Implementations.HttpServer
|
||||
{
|
||||
@@ -30,7 +28,20 @@ namespace Emby.Server.Implementations.HttpServer
|
||||
}
|
||||
else
|
||||
{
|
||||
var headerText = string.Join(", ", headers.Select(i => i.Name + "=" + i.Value).ToArray(headers.Count));
|
||||
var headerText = string.Empty;
|
||||
var index = 0;
|
||||
|
||||
foreach (var i in headers)
|
||||
{
|
||||
if (index > 0)
|
||||
{
|
||||
headerText += ", ";
|
||||
}
|
||||
|
||||
headerText += i.Name + "=" + i.Value;
|
||||
|
||||
index++;
|
||||
}
|
||||
|
||||
logger.Info("HTTP {0} {1}. {2}", method, url, headerText);
|
||||
}
|
||||
@@ -49,7 +60,8 @@ namespace Emby.Server.Implementations.HttpServer
|
||||
var durationMs = duration.TotalMilliseconds;
|
||||
var logSuffix = durationMs >= 1000 && durationMs < 60000 ? "ms (slow)" : "ms";
|
||||
|
||||
var headerText = headers == null ? string.Empty : "Headers: " + string.Join(", ", headers.Where(i => i.Name.IndexOf("Access-", StringComparison.OrdinalIgnoreCase) == -1).Select(i => i.Name + "=" + i.Value).ToArray());
|
||||
//var headerText = headers == null ? string.Empty : "Headers: " + string.Join(", ", headers.Where(i => i.Name.IndexOf("Access-", StringComparison.OrdinalIgnoreCase) == -1).Select(i => i.Name + "=" + i.Value).ToArray());
|
||||
var headerText = string.Empty;
|
||||
logger.Info("HTTP Response {0} to {1}. Time: {2}{3}. {4} {5}", statusCode, endPoint, Convert.ToInt32(durationMs).ToString(CultureInfo.InvariantCulture), logSuffix, url, headerText);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ using MediaBrowser.Controller.Net;
|
||||
using MediaBrowser.Controller.Security;
|
||||
using MediaBrowser.Controller.Session;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Emby.Server.Implementations.HttpServer.Security
|
||||
@@ -78,7 +77,7 @@ namespace Emby.Server.Implementations.HttpServer.Security
|
||||
|
||||
if (!IsExemptFromRoles(auth, authAttribtues, info))
|
||||
{
|
||||
var roles = authAttribtues.GetRoles().ToList();
|
||||
var roles = authAttribtues.GetRoles();
|
||||
|
||||
ValidateRoles(roles, user);
|
||||
}
|
||||
@@ -162,7 +161,7 @@ namespace Emby.Server.Implementations.HttpServer.Security
|
||||
return false;
|
||||
}
|
||||
|
||||
private void ValidateRoles(List<string> roles, User user)
|
||||
private void ValidateRoles(string[] roles, User user)
|
||||
{
|
||||
if (roles.Contains("admin", StringComparer.OrdinalIgnoreCase))
|
||||
{
|
||||
|
||||
@@ -3,8 +3,8 @@ using MediaBrowser.Controller.Net;
|
||||
using MediaBrowser.Controller.Security;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using MediaBrowser.Model.Services;
|
||||
using System.Linq;
|
||||
|
||||
namespace Emby.Server.Implementations.HttpServer.Security
|
||||
{
|
||||
@@ -90,7 +90,7 @@ namespace Emby.Server.Implementations.HttpServer.Security
|
||||
AccessToken = token
|
||||
});
|
||||
|
||||
var tokenInfo = result.Items.FirstOrDefault();
|
||||
var tokenInfo = result.Items.Length > 0 ? result.Items[0] : null;
|
||||
|
||||
if (tokenInfo != null)
|
||||
{
|
||||
@@ -161,7 +161,7 @@ namespace Emby.Server.Implementations.HttpServer.Security
|
||||
// There should be at least to parts
|
||||
if (parts.Length != 2) return null;
|
||||
|
||||
var acceptedNames = new[] { "MediaBrowser", "Emby"};
|
||||
var acceptedNames = new[] { "MediaBrowser", "Emby" };
|
||||
|
||||
// It has to be a digest request
|
||||
if (!acceptedNames.Contains(parts[0] ?? string.Empty, StringComparer.OrdinalIgnoreCase))
|
||||
|
||||
Reference in New Issue
Block a user