diff options
Diffstat (limited to 'Emby.Server.Implementations/HttpServer')
3 files changed, 26 insertions, 24 deletions
diff --git a/Emby.Server.Implementations/HttpServer/FileWriter.cs b/Emby.Server.Implementations/HttpServer/FileWriter.cs index c1c8c3eb3..82f1e5b52 100644 --- a/Emby.Server.Implementations/HttpServer/FileWriter.cs +++ b/Emby.Server.Implementations/HttpServer/FileWriter.cs @@ -71,7 +71,7 @@ namespace Emby.Server.Implementations.HttpServer SetRangeValues(); } - FileShare = FileShareMode.Read; + FileShare = FileShare.Read; Cookies = new List<Cookie>(); } @@ -93,7 +93,7 @@ namespace Emby.Server.Implementations.HttpServer public List<Cookie> Cookies { get; private set; } - public FileShareMode FileShare { get; set; } + public FileShare FileShare { get; set; } /// <summary> /// Gets the options. @@ -221,17 +221,17 @@ namespace Emby.Server.Implementations.HttpServer } } - public async Task TransmitFile(Stream stream, string path, long offset, long count, FileShareMode fileShareMode, CancellationToken cancellationToken) + public async Task TransmitFile(Stream stream, string path, long offset, long count, FileShare fileShare, CancellationToken cancellationToken) { - var fileOpenOptions = FileOpenOptions.SequentialScan; + var fileOptions = FileOptions.SequentialScan; // use non-async filestream along with read due to https://github.com/dotnet/corefx/issues/6039 if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { - fileOpenOptions |= FileOpenOptions.Asynchronous; + fileOptions |= FileOptions.Asynchronous; } - using (var fs = _fileSystem.GetFileStream(path, FileOpenMode.Open, FileAccessMode.Read, fileShareMode, fileOpenOptions)) + using (var fs = new FileStream(path, FileMode.Open, FileAccess.Read, fileShare, IODefaults.FileStreamBufferSize, fileOptions)) { if (offset > 0) { @@ -244,7 +244,7 @@ namespace Emby.Server.Implementations.HttpServer } else { - await fs.CopyToAsync(stream, StreamDefaults.DefaultCopyToBufferSize, cancellationToken).ConfigureAwait(false); + await fs.CopyToAsync(stream, IODefaults.CopyToBufferSize, cancellationToken).ConfigureAwait(false); } } } diff --git a/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs b/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs index 2aefc9fe5..93572b8bf 100644 --- a/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs +++ b/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs @@ -39,9 +39,9 @@ namespace Emby.Server.Implementations.HttpServer private readonly Func<Type, Func<string, object>> _funcParseFn; private readonly string _defaultRedirectPath; private readonly string _baseUrlPrefix; - private readonly Dictionary<Type, Type> ServiceOperationsMap = new Dictionary<Type, Type>(); - private IWebSocketListener[] _webSocketListeners = Array.Empty<IWebSocketListener>(); + private readonly Dictionary<Type, Type> _serviceOperationsMap = new Dictionary<Type, Type>(); private readonly List<IWebSocketConnection> _webSocketConnections = new List<IWebSocketConnection>(); + private IWebSocketListener[] _webSocketListeners = Array.Empty<IWebSocketListener>(); private bool _disposed = false; public HttpListenerHost( @@ -71,6 +71,8 @@ namespace Emby.Server.Implementations.HttpServer ResponseFilters = Array.Empty<Action<IRequest, HttpResponse, object>>(); } + public event EventHandler<GenericEventArgs<IWebSocketConnection>> WebSocketConnected; + public Action<IRequest, HttpResponse, object>[] ResponseFilters { get; set; } public static HttpListenerHost Instance { get; protected set; } @@ -81,8 +83,6 @@ namespace Emby.Server.Implementations.HttpServer public ServiceController ServiceController { get; private set; } - public event EventHandler<GenericEventArgs<IWebSocketConnection>> WebSocketConnected; - public object CreateInstance(Type type) { return _appHost.CreateInstance(type); @@ -90,7 +90,7 @@ namespace Emby.Server.Implementations.HttpServer private static string NormalizeUrlPath(string path) { - if (path.StartsWith("/")) + if (path.Length > 0 && path[0] == '/') { // If the path begins with a leading slash, just return it as-is return path; @@ -130,13 +130,13 @@ namespace Emby.Server.Implementations.HttpServer public Type GetServiceTypeByRequest(Type requestType) { - ServiceOperationsMap.TryGetValue(requestType, out var serviceType); + _serviceOperationsMap.TryGetValue(requestType, out var serviceType); return serviceType; } public void AddServiceInfo(Type serviceType, Type requestType) { - ServiceOperationsMap[requestType] = serviceType; + _serviceOperationsMap[requestType] = serviceType; } private List<IHasRequestFilter> GetRequestFilterAttributes(Type requestDtoType) @@ -198,7 +198,7 @@ namespace Emby.Server.Implementations.HttpServer else { var inners = agg.InnerExceptions; - if (inners != null && inners.Count > 0) + if (inners.Count > 0) { return GetActualException(inners[0]); } @@ -218,7 +218,6 @@ namespace Emby.Server.Implementations.HttpServer case FileNotFoundException _: case ResourceNotFoundException _: return 404; case MethodNotAllowedException _: return 405; - case RemoteServiceUnavailableException _: return 502; default: return 500; } } @@ -362,7 +361,7 @@ namespace Emby.Server.Implementations.HttpServer return true; } - host = host ?? string.Empty; + host ??= string.Empty; if (_networkManager.IsInPrivateAddressSpace(host)) { @@ -433,7 +432,7 @@ namespace Emby.Server.Implementations.HttpServer } /// <summary> - /// Overridable method that can be used to implement a custom hnandler + /// Overridable method that can be used to implement a custom handler. /// </summary> public async Task RequestHandler(IHttpRequest httpReq, string urlString, string host, string localPath, CancellationToken cancellationToken) { @@ -492,7 +491,7 @@ namespace Emby.Server.Implementations.HttpServer || string.Equals(localPath, _baseUrlPrefix, StringComparison.OrdinalIgnoreCase) || string.Equals(localPath, "/", StringComparison.OrdinalIgnoreCase) || string.IsNullOrEmpty(localPath) - || !localPath.StartsWith(_baseUrlPrefix)) + || !localPath.StartsWith(_baseUrlPrefix, StringComparison.OrdinalIgnoreCase)) { // Always redirect back to the default path if the base prefix is invalid or missing _logger.LogDebug("Normalizing a URL at {0}", localPath); @@ -693,7 +692,10 @@ namespace Emby.Server.Implementations.HttpServer protected virtual void Dispose(bool disposing) { - if (_disposed) return; + if (_disposed) + { + return; + } if (disposing) { diff --git a/Emby.Server.Implementations/HttpServer/HttpResultFactory.cs b/Emby.Server.Implementations/HttpServer/HttpResultFactory.cs index a62b4e7af..b42662420 100644 --- a/Emby.Server.Implementations/HttpServer/HttpResultFactory.cs +++ b/Emby.Server.Implementations/HttpServer/HttpResultFactory.cs @@ -439,7 +439,7 @@ namespace Emby.Server.Implementations.HttpServer public Task<object> GetStaticFileResult(IRequest requestContext, string path, - FileShareMode fileShare = FileShareMode.Read) + FileShare fileShare = FileShare.Read) { if (string.IsNullOrEmpty(path)) { @@ -463,7 +463,7 @@ namespace Emby.Server.Implementations.HttpServer throw new ArgumentException("Path can't be empty.", nameof(options)); } - if (fileShare != FileShareMode.Read && fileShare != FileShareMode.ReadWrite) + if (fileShare != FileShare.Read && fileShare != FileShare.ReadWrite) { throw new ArgumentException("FileShare must be either Read or ReadWrite"); } @@ -491,9 +491,9 @@ namespace Emby.Server.Implementations.HttpServer /// <param name="path">The path.</param> /// <param name="fileShare">The file share.</param> /// <returns>Stream.</returns> - private Stream GetFileStream(string path, FileShareMode fileShare) + private Stream GetFileStream(string path, FileShare fileShare) { - return _fileSystem.GetFileStream(path, FileOpenMode.Open, FileAccessMode.Read, fileShare); + return new FileStream(path, FileMode.Open, FileAccess.Read, fileShare); } public Task<object> GetStaticResult(IRequest requestContext, |
