aboutsummaryrefslogtreecommitdiff
path: root/Jellyfin.Server
diff options
context:
space:
mode:
authorLogicalPhallacy <44458166+LogicalPhallacy@users.noreply.github.com>2019-01-23 00:31:35 -0800
committerGitHub <noreply@github.com>2019-01-23 00:31:35 -0800
commit404bd04cbc17dc8c8bf4a5c9aa3ca9c5cd85aa68 (patch)
tree3d267c6ceef9439a034c113095e10e4d619e7c70 /Jellyfin.Server
parent8ff89fdc0c30f595a171ffc550f907ef22b6212a (diff)
parente05e002b8bb4d13eb2b80b56a0aad8903ddb701e (diff)
Merge pull request #8 from jellyfin/master
rebase to latest master
Diffstat (limited to 'Jellyfin.Server')
-rw-r--r--Jellyfin.Server/CoreAppHost.cs24
-rw-r--r--Jellyfin.Server/Jellyfin.Server.csproj11
-rw-r--r--Jellyfin.Server/PowerManagement.cs23
-rw-r--r--Jellyfin.Server/Program.cs650
-rw-r--r--Jellyfin.Server/Properties/AssemblyInfo.cs21
-rw-r--r--Jellyfin.Server/Resources/Configuration/logging.json19
-rw-r--r--Jellyfin.Server/SocketSharp/HttpFile.cs2
-rw-r--r--Jellyfin.Server/SocketSharp/RequestMono.cs117
-rw-r--r--Jellyfin.Server/SocketSharp/SharpWebSocket.cs14
-rw-r--r--Jellyfin.Server/SocketSharp/WebSocketSharpListener.cs12
-rw-r--r--Jellyfin.Server/SocketSharp/WebSocketSharpRequest.cs174
-rw-r--r--Jellyfin.Server/SocketSharp/WebSocketSharpResponse.cs36
12 files changed, 504 insertions, 599 deletions
diff --git a/Jellyfin.Server/CoreAppHost.cs b/Jellyfin.Server/CoreAppHost.cs
index b546343871..6832fe7431 100644
--- a/Jellyfin.Server/CoreAppHost.cs
+++ b/Jellyfin.Server/CoreAppHost.cs
@@ -11,41 +11,27 @@ namespace Jellyfin.Server
{
public class CoreAppHost : ApplicationHost
{
- public CoreAppHost(ServerApplicationPaths applicationPaths, ILoggerFactory loggerFactory, StartupOptions options, IFileSystem fileSystem, IPowerManagement powerManagement, IEnvironmentInfo environmentInfo, MediaBrowser.Controller.Drawing.IImageEncoder imageEncoder, ISystemEvents systemEvents, MediaBrowser.Common.Net.INetworkManager networkManager)
- : base(applicationPaths, loggerFactory, options, fileSystem, powerManagement, environmentInfo, imageEncoder, systemEvents, networkManager)
+ public CoreAppHost(ServerApplicationPaths applicationPaths, ILoggerFactory loggerFactory, StartupOptions options, IFileSystem fileSystem, IEnvironmentInfo environmentInfo, MediaBrowser.Controller.Drawing.IImageEncoder imageEncoder, ISystemEvents systemEvents, MediaBrowser.Common.Net.INetworkManager networkManager)
+ : base(applicationPaths, loggerFactory, options, fileSystem, environmentInfo, imageEncoder, systemEvents, networkManager)
{
}
- public override bool CanSelfRestart
- {
- get
- {
- // A restart script must be provided
- return StartupOptions.ContainsOption("-restartpath");
- }
- }
+ public override bool CanSelfRestart => StartupOptions.ContainsOption("-restartpath");
protected override void RestartInternal() => Program.Restart();
protected override IEnumerable<Assembly> GetAssembliesWithPartsInternal()
- => new [] { typeof(CoreAppHost).Assembly };
+ => new[] { typeof(CoreAppHost).Assembly };
protected override void ShutdownInternal() => Program.Shutdown();
- protected override bool SupportsDualModeSockets
- {
- get
- {
- return true;
- }
- }
+ protected override bool SupportsDualModeSockets => true;
protected override IHttpListener CreateHttpListener()
=> new WebSocketSharpListener(
Logger,
Certificate,
StreamHelper,
- TextEncoding,
NetworkManager,
SocketFactory,
CryptographyProvider,
diff --git a/Jellyfin.Server/Jellyfin.Server.csproj b/Jellyfin.Server/Jellyfin.Server.csproj
index 8ecae1b5bf..897d933396 100644
--- a/Jellyfin.Server/Jellyfin.Server.csproj
+++ b/Jellyfin.Server/Jellyfin.Server.csproj
@@ -1,4 +1,4 @@
-<Project Sdk="Microsoft.NET.Sdk">
+<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AssemblyName>jellyfin</AssemblyName>
@@ -20,11 +20,19 @@
<EmbeddedResource Include="Resources/Configuration/*" />
</ItemGroup>
+ <!-- Code analysers-->
+ <ItemGroup Condition=" '$(Configuration)' == 'Debug' ">
+ <PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.6.3" />
+ <PackageReference Include="StyleCop.Analyzers" Version="1.0.2" />
+ <PackageReference Include="SerilogAnalyzer" Version="0.15.0" />
+ </ItemGroup>
+
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.2.0" />
<PackageReference Include="Serilog.AspNetCore" Version="2.1.1" />
<PackageReference Include="Serilog.Settings.Configuration" Version="3.0.1" />
+ <PackageReference Include="Serilog.Sinks.Async" Version="1.3.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" />
<PackageReference Include="Serilog.Sinks.File" Version="4.0.0" />
<PackageReference Include="SkiaSharp" Version="1.68.0" />
@@ -35,7 +43,6 @@
<ItemGroup>
<ProjectReference Include="..\Emby.Drawing\Emby.Drawing.csproj" />
- <ProjectReference Include="..\Emby.Drawing.Skia\Emby.Drawing.Skia.csproj" />
<ProjectReference Include="..\Emby.IsoMounting\IsoMounter\IsoMounter.csproj" />
<ProjectReference Include="..\Emby.Server.Implementations\Emby.Server.Implementations.csproj" />
</ItemGroup>
diff --git a/Jellyfin.Server/PowerManagement.cs b/Jellyfin.Server/PowerManagement.cs
deleted file mode 100644
index c27c518937..0000000000
--- a/Jellyfin.Server/PowerManagement.cs
+++ /dev/null
@@ -1,23 +0,0 @@
-using System;
-using MediaBrowser.Model.System;
-
-namespace Jellyfin.Server.Native
-{
- public class PowerManagement : IPowerManagement
- {
- public void PreventSystemStandby()
- {
-
- }
-
- public void AllowSystemStandby()
- {
-
- }
-
- public void ScheduleWake(DateTime wakeTimeUtc, string displayName)
- {
-
- }
- }
-}
diff --git a/Jellyfin.Server/Program.cs b/Jellyfin.Server/Program.cs
index 2dd4d9af66..0510548b56 100644
--- a/Jellyfin.Server/Program.cs
+++ b/Jellyfin.Server/Program.cs
@@ -1,290 +1,360 @@
-using System;
-using System.Diagnostics;
-using System.IO;
-using System.Linq;
-using System.Net;
-using System.Net.Security;
-using System.Reflection;
-using System.Runtime.InteropServices;
-using System.Threading.Tasks;
-using Emby.Drawing;
-using Emby.Drawing.Skia;
-using Emby.Server.Implementations;
-using Emby.Server.Implementations.EnvironmentInfo;
-using Emby.Server.Implementations.IO;
-using Emby.Server.Implementations.Networking;
-using Jellyfin.Server.Native;
-using MediaBrowser.Common.Configuration;
-using MediaBrowser.Common.Net;
-using MediaBrowser.Controller.Drawing;
-using MediaBrowser.Model.IO;
-using MediaBrowser.Model.Globalization;
-using MediaBrowser.Model.System;
-using Microsoft.Extensions.Configuration;
-using Microsoft.Extensions.Logging;
-using Serilog;
-using Serilog.AspNetCore;
-using ILogger = Microsoft.Extensions.Logging.ILogger;
-
-namespace Jellyfin.Server
-{
- public static class Program
- {
- private static readonly TaskCompletionSource<bool> ApplicationTaskCompletionSource = new TaskCompletionSource<bool>();
- private static ILoggerFactory _loggerFactory;
- private static ILogger _logger;
- private static bool _restartOnShutdown;
-
- public static async Task<int> Main(string[] args)
- {
- StartupOptions options = new StartupOptions(args);
- Version version = Assembly.GetEntryAssembly().GetName().Version;
-
- if (options.ContainsOption("-v") || options.ContainsOption("--version"))
- {
- Console.WriteLine(version.ToString());
- return 0;
- }
-
- ServerApplicationPaths appPaths = createApplicationPaths(options);
- await createLogger(appPaths);
- _loggerFactory = new SerilogLoggerFactory();
- _logger = _loggerFactory.CreateLogger("Main");
-
- AppDomain.CurrentDomain.UnhandledException += (sender, e)
- => _logger.LogCritical((Exception)e.ExceptionObject, "Unhandled Exception");
-
- _logger.LogInformation("Jellyfin version: {Version}", version);
-
- EnvironmentInfo environmentInfo = new EnvironmentInfo(getOperatingSystem());
- ApplicationHost.LogEnvironmentInfo(_logger, appPaths, environmentInfo);
-
- SQLitePCL.Batteries_V2.Init();
-
- // Allow all https requests
- ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(delegate { return true; });
-
- var fileSystem = new ManagedFileSystem(_loggerFactory.CreateLogger("FileSystem"), environmentInfo, null, appPaths.TempDirectory, true);
-
- using (var appHost = new CoreAppHost(
- appPaths,
- _loggerFactory,
- options,
- fileSystem,
- new PowerManagement(),
- environmentInfo,
- new NullImageEncoder(),
- new SystemEvents(_loggerFactory.CreateLogger("SystemEvents")),
- new NetworkManager(_loggerFactory.CreateLogger("NetworkManager"), environmentInfo)))
- {
- appHost.Init();
-
- appHost.ImageProcessor.ImageEncoder = getImageEncoder(_logger, fileSystem, options, () => appHost.HttpClient, appPaths, environmentInfo, appHost.LocalizationManager);
-
- _logger.LogInformation("Running startup tasks");
-
- await appHost.RunStartupTasks();
-
- // TODO: read input for a stop command
- // Block main thread until shutdown
- await ApplicationTaskCompletionSource.Task;
-
- _logger.LogInformation("Disposing app host");
- }
-
- if (_restartOnShutdown)
- {
- StartNewInstance(options);
- }
-
- return 0;
- }
-
- private static ServerApplicationPaths createApplicationPaths(StartupOptions options)
- {
- string programDataPath;
- if (options.ContainsOption("-programdata"))
- {
- programDataPath = options.GetOption("-programdata");
- }
- else
- {
- if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
- {
- programDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
- }
- else
- {
- // $XDG_DATA_HOME defines the base directory relative to which user specific data files should be stored.
- programDataPath = Environment.GetEnvironmentVariable("XDG_DATA_HOME");
- // If $XDG_DATA_HOME is either not set or empty, $HOME/.local/share should be used.
- if (string.IsNullOrEmpty(programDataPath))
- {
- programDataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".local", "share");
- }
- }
- programDataPath = Path.Combine(programDataPath, "jellyfin");
- }
-
- string logDir = Environment.GetEnvironmentVariable("JELLYFIN_LOG_DIR");
- if (string.IsNullOrEmpty(logDir))
- {
- logDir = Path.Combine(programDataPath, "logs");
- // Ensure logDir exists
- Directory.CreateDirectory(logDir);
- // $JELLYFIN_LOG_DIR needs to be set for the logger configuration manager
- Environment.SetEnvironmentVariable("JELLYFIN_LOG_DIR", logDir);
- }
-
- string appPath = AppContext.BaseDirectory;
-
- return new ServerApplicationPaths(programDataPath, appPath, appPath, logDir);
- }
-
- private static async Task createLogger(IApplicationPaths appPaths)
- {
- try
- {
- string configPath = Path.Combine(appPaths.ConfigurationDirectoryPath, "logging.json");
-
- if (!File.Exists(configPath))
- {
- // For some reason the csproj name is used instead of the assembly name
- using (Stream rscstr = typeof(Program).Assembly
- .GetManifestResourceStream("Jellyfin.Server.Resources.Configuration.logging.json"))
- using (Stream fstr = File.Open(configPath, FileMode.CreateNew))
- {
- await rscstr.CopyToAsync(fstr);
- }
- }
- var configuration = new ConfigurationBuilder()
- .SetBasePath(appPaths.ConfigurationDirectoryPath)
- .AddJsonFile("logging.json")
- .AddEnvironmentVariables("JELLYFIN_")
- .Build();
-
- // Serilog.Log is used by SerilogLoggerFactory when no logger is specified
- Serilog.Log.Logger = new LoggerConfiguration()
- .ReadFrom.Configuration(configuration)
- .Enrich.FromLogContext()
- .CreateLogger();
- }
- catch (Exception ex)
- {
- Serilog.Log.Logger = new LoggerConfiguration()
- .WriteTo.Console(outputTemplate: "[{Timestamp:HH:mm:ss}] [{Level:u3}] {Message:lj}{NewLine}{Exception}")
- .WriteTo.File(
- Path.Combine(appPaths.LogDirectoryPath, "log_.log"),
- rollingInterval: RollingInterval.Day,
- outputTemplate: "[{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz}] [{Level:u3}] {Message}{NewLine}{Exception}")
- .Enrich.FromLogContext()
- .CreateLogger();
-
- Serilog.Log.Logger.Fatal(ex, "Failed to create/read logger configuration");
- }
- }
-
- public static IImageEncoder getImageEncoder(
- ILogger logger,
- IFileSystem fileSystem,
- StartupOptions startupOptions,
- Func<IHttpClient> httpClient,
- IApplicationPaths appPaths,
- IEnvironmentInfo environment,
- ILocalizationManager localizationManager)
- {
- try
- {
- return new SkiaEncoder(logger, appPaths, httpClient, fileSystem, localizationManager);
- }
- catch (Exception ex)
- {
- logger.LogInformation(ex, "Skia not available. Will fallback to NullIMageEncoder. {0}");
- }
-
- return new NullImageEncoder();
- }
-
- private static MediaBrowser.Model.System.OperatingSystem getOperatingSystem() {
- switch (Environment.OSVersion.Platform)
- {
- case PlatformID.MacOSX:
- return MediaBrowser.Model.System.OperatingSystem.OSX;
- case PlatformID.Win32NT:
- return MediaBrowser.Model.System.OperatingSystem.Windows;
- case PlatformID.Unix:
- default:
- {
- string osDescription = RuntimeInformation.OSDescription;
- if (osDescription.Contains("linux", StringComparison.OrdinalIgnoreCase))
- {
- return MediaBrowser.Model.System.OperatingSystem.Linux;
- }
- else if (osDescription.Contains("darwin", StringComparison.OrdinalIgnoreCase))
- {
- return MediaBrowser.Model.System.OperatingSystem.OSX;
- }
- else if (osDescription.Contains("bsd", StringComparison.OrdinalIgnoreCase))
- {
- return MediaBrowser.Model.System.OperatingSystem.BSD;
- }
- throw new Exception($"Can't resolve OS with description: '{osDescription}'");
- }
- }
- }
-
- public static void Shutdown()
- {
- ApplicationTaskCompletionSource.SetResult(true);
- }
-
- public static void Restart()
- {
- _restartOnShutdown = true;
-
- Shutdown();
- }
-
- private static void StartNewInstance(StartupOptions startupOptions)
- {
- _logger.LogInformation("Starting new instance");
-
- string module = startupOptions.GetOption("-restartpath");
-
- if (string.IsNullOrWhiteSpace(module))
- {
- module = Environment.GetCommandLineArgs().First();
- }
-
- string commandLineArgsString;
-
- if (startupOptions.ContainsOption("-restartargs"))
- {
- commandLineArgsString = startupOptions.GetOption("-restartargs") ?? string.Empty;
- }
- else
- {
- commandLineArgsString = string .Join(" ",
- Environment.GetCommandLineArgs()
- .Skip(1)
- .Select(NormalizeCommandLineArgument)
- );
- }
-
- _logger.LogInformation("Executable: {0}", module);
- _logger.LogInformation("Arguments: {0}", commandLineArgsString);
-
- Process.Start(module, commandLineArgsString);
- }
-
- private static string NormalizeCommandLineArgument(string arg)
- {
- if (!arg.Contains(" ", StringComparison.OrdinalIgnoreCase))
- {
- return arg;
- }
-
- return "\"" + arg + "\"";
- }
- }
-}
+using System;
+using System.Diagnostics;
+using System.IO;
+using System.Linq;
+using System.Net;
+using System.Net.Security;
+using System.Reflection;
+using System.Runtime.InteropServices;
+using System.Threading;
+using System.Threading.Tasks;
+using Emby.Drawing;
+using Emby.Server.Implementations;
+using Emby.Server.Implementations.EnvironmentInfo;
+using Emby.Server.Implementations.IO;
+using Emby.Server.Implementations.Networking;
+using MediaBrowser.Common.Configuration;
+using MediaBrowser.Controller.Drawing;
+using MediaBrowser.Model.Globalization;
+using MediaBrowser.Model.IO;
+using Microsoft.Extensions.Configuration;
+using Microsoft.Extensions.Logging;
+using Serilog;
+using Serilog.AspNetCore;
+using ILogger = Microsoft.Extensions.Logging.ILogger;
+
+namespace Jellyfin.Server
+{
+ public static class Program
+ {
+ private static readonly CancellationTokenSource _tokenSource = new CancellationTokenSource();
+ private static readonly ILoggerFactory _loggerFactory = new SerilogLoggerFactory();
+ private static ILogger _logger;
+ private static bool _restartOnShutdown;
+
+ public static async Task Main(string[] args)
+ {
+ StartupOptions options = new StartupOptions(args);
+ Version version = Assembly.GetEntryAssembly().GetName().Version;
+
+ if (options.ContainsOption("-v") || options.ContainsOption("--version"))
+ {
+ Console.WriteLine(version.ToString());
+ }
+
+ ServerApplicationPaths appPaths = CreateApplicationPaths(options);
+
+ // $JELLYFIN_LOG_DIR needs to be set for the logger configuration manager
+ Environment.SetEnvironmentVariable("JELLYFIN_LOG_DIR", appPaths.LogDirectoryPath);
+ await createLogger(appPaths);
+ _logger = _loggerFactory.CreateLogger("Main");
+
+ AppDomain.CurrentDomain.UnhandledException += (sender, e)
+ => _logger.LogCritical((Exception)e.ExceptionObject, "Unhandled Exception");
+
+ // Intercept Ctrl+C and Ctrl+Break
+ Console.CancelKeyPress += (sender, e) =>
+ {
+ if (_tokenSource.IsCancellationRequested)
+ {
+ return; // Already shutting down
+ }
+ e.Cancel = true;
+ _logger.LogInformation("Ctrl+C, shutting down");
+ Environment.ExitCode = 128 + 2;
+ Shutdown();
+ };
+
+ // Register a SIGTERM handler
+ AppDomain.CurrentDomain.ProcessExit += (sender, e) =>
+ {
+ if (_tokenSource.IsCancellationRequested)
+ {
+ return; // Already shutting down
+ }
+ _logger.LogInformation("Received a SIGTERM signal, shutting down");
+ Environment.ExitCode = 128 + 15;
+ Shutdown();
+ };
+
+ _logger.LogInformation("Jellyfin version: {Version}", version);
+
+ EnvironmentInfo environmentInfo = new EnvironmentInfo(getOperatingSystem());
+ ApplicationHost.LogEnvironmentInfo(_logger, appPaths, environmentInfo);
+
+ SQLitePCL.Batteries_V2.Init();
+
+ // Allow all https requests
+ ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(delegate { return true; });
+
+ var fileSystem = new ManagedFileSystem(_loggerFactory, environmentInfo, null, appPaths.TempDirectory, true);
+
+ using (var appHost = new CoreAppHost(
+ appPaths,
+ _loggerFactory,
+ options,
+ fileSystem,
+ environmentInfo,
+ new NullImageEncoder(),
+ new SystemEvents(),
+ new NetworkManager(_loggerFactory, environmentInfo)))
+ {
+ appHost.Init();
+
+ appHost.ImageProcessor.ImageEncoder = GetImageEncoder(fileSystem, appPaths, appHost.LocalizationManager);
+
+ _logger.LogInformation("Running startup tasks");
+
+ await appHost.RunStartupTasks();
+
+ // TODO: read input for a stop command
+
+ try
+ {
+ // Block main thread until shutdown
+ await Task.Delay(-1, _tokenSource.Token);
+ }
+ catch (TaskCanceledException)
+ {
+ // Don't throw on cancellation
+ }
+
+ _logger.LogInformation("Disposing app host");
+ }
+
+ if (_restartOnShutdown)
+ {
+ StartNewInstance(options);
+ }
+ }
+
+ private static ServerApplicationPaths CreateApplicationPaths(StartupOptions options)
+ {
+ string programDataPath = Environment.GetEnvironmentVariable("JELLYFIN_DATA_PATH");
+ if (string.IsNullOrEmpty(programDataPath))
+ {
+ if (options.ContainsOption("-programdata"))
+ {
+ programDataPath = options.GetOption("-programdata");
+ }
+ else
+ {
+ if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+ {
+ programDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
+ }
+ else
+ {
+ // $XDG_DATA_HOME defines the base directory relative to which user specific data files should be stored.
+ programDataPath = Environment.GetEnvironmentVariable("XDG_DATA_HOME");
+ // If $XDG_DATA_HOME is either not set or empty, $HOME/.local/share should be used.
+ if (string.IsNullOrEmpty(programDataPath))
+ {
+ programDataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".local", "share");
+ }
+ }
+
+ programDataPath = Path.Combine(programDataPath, "jellyfin");
+ }
+ }
+
+ if (string.IsNullOrEmpty(programDataPath))
+ {
+ Console.WriteLine("Cannot continue without path to program data folder (try -programdata)");
+ Environment.Exit(1);
+ }
+ else
+ {
+ Directory.CreateDirectory(programDataPath);
+ }
+
+ string configDir = Environment.GetEnvironmentVariable("JELLYFIN_CONFIG_DIR");
+ if (string.IsNullOrEmpty(configDir))
+ {
+ if (options.ContainsOption("-configdir"))
+ {
+ configDir = options.GetOption("-configdir");
+ }
+ else
+ {
+ // Let BaseApplicationPaths set up the default value
+ configDir = null;
+ }
+ }
+
+ if (configDir != null)
+ {
+ Directory.CreateDirectory(configDir);
+ }
+
+ string logDir = Environment.GetEnvironmentVariable("JELLYFIN_LOG_DIR");
+ if (string.IsNullOrEmpty(logDir))
+ {
+ if (options.ContainsOption("-logdir"))
+ {
+ logDir = options.GetOption("-logdir");
+ }
+ else
+ {
+ // Let BaseApplicationPaths set up the default value
+ logDir = null;
+ }
+ }
+
+ if (logDir != null)
+ {
+ Directory.CreateDirectory(logDir);
+ }
+
+ string appPath = AppContext.BaseDirectory;
+
+ return new ServerApplicationPaths(programDataPath, appPath, appPath, logDir, configDir);
+ }
+
+ private static async Task createLogger(IApplicationPaths appPaths)
+ {
+ try
+ {
+ string configPath = Path.Combine(appPaths.ConfigurationDirectoryPath, "logging.json");
+
+ if (!File.Exists(configPath))
+ {
+ // For some reason the csproj name is used instead of the assembly name
+ using (Stream rscstr = typeof(Program).Assembly
+ .GetManifestResourceStream("Jellyfin.Server.Resources.Configuration.logging.json"))
+ using (Stream fstr = File.Open(configPath, FileMode.CreateNew))
+ {
+ await rscstr.CopyToAsync(fstr);
+ }
+ }
+ var configuration = new ConfigurationBuilder()
+ .SetBasePath(appPaths.ConfigurationDirectoryPath)
+ .AddJsonFile("logging.json")
+ .AddEnvironmentVariables("JELLYFIN_")
+ .Build();
+
+ // Serilog.Log is used by SerilogLoggerFactory when no logger is specified
+ Serilog.Log.Logger = new LoggerConfiguration()
+ .ReadFrom.Configuration(configuration)
+ .Enrich.FromLogContext()
+ .CreateLogger();
+ }
+ catch (Exception ex)
+ {
+ Serilog.Log.Logger = new LoggerConfiguration()
+ .WriteTo.Console(outputTemplate: "[{Timestamp:HH:mm:ss}] [{Level:u3}] {Message:lj}{NewLine}{Exception}")
+ .WriteTo.Async(x => x.File(
+ Path.Combine(appPaths.LogDirectoryPath, "log_.log"),
+ rollingInterval: RollingInterval.Day,
+ outputTemplate: "[{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz}] [{Level:u3}] {Message}{NewLine}{Exception}"))
+ .Enrich.FromLogContext()
+ .CreateLogger();
+
+ Serilog.Log.Logger.Fatal(ex, "Failed to create/read logger configuration");
+ }
+ }
+
+ public static IImageEncoder GetImageEncoder(
+ IFileSystem fileSystem,
+ IApplicationPaths appPaths,
+ ILocalizationManager localizationManager)
+ {
+ try
+ {
+ return new SkiaEncoder(_loggerFactory, appPaths, fileSystem, localizationManager);
+ }
+ catch (Exception ex)
+ {
+ _logger.LogInformation(ex, "Skia not available. Will fallback to NullIMageEncoder. {0}");
+ }
+
+ return new NullImageEncoder();
+ }
+
+ private static MediaBrowser.Model.System.OperatingSystem getOperatingSystem()
+ {
+ switch (Environment.OSVersion.Platform)
+ {
+ case PlatformID.MacOSX:
+ return MediaBrowser.Model.System.OperatingSystem.OSX;
+ case PlatformID.Win32NT:
+ return MediaBrowser.Model.System.OperatingSystem.Windows;
+ case PlatformID.Unix:
+ default:
+ {
+ string osDescription = RuntimeInformation.OSDescription;
+ if (osDescription.Contains("linux", StringComparison.OrdinalIgnoreCase))
+ {
+ return MediaBrowser.Model.System.OperatingSystem.Linux;
+ }
+ else if (osDescription.Contains("darwin", StringComparison.OrdinalIgnoreCase))
+ {
+ return MediaBrowser.Model.System.OperatingSystem.OSX;
+ }
+ else if (osDescription.Contains("bsd", StringComparison.OrdinalIgnoreCase))
+ {
+ return MediaBrowser.Model.System.OperatingSystem.BSD;
+ }
+ throw new Exception($"Can't resolve OS with description: '{osDescription}'");
+ }
+ }
+ }
+
+ public static void Shutdown()
+ {
+ if (!_tokenSource.IsCancellationRequested)
+ {
+ _tokenSource.Cancel();
+ }
+ }
+
+ public static void Restart()
+ {
+ _restartOnShutdown = true;
+
+ Shutdown();
+ }
+
+ private static void StartNewInstance(StartupOptions startupOptions)
+ {
+ _logger.LogInformation("Starting new instance");
+
+ string module = startupOptions.GetOption("-restartpath");
+
+ if (string.IsNullOrWhiteSpace(module))
+ {
+ module = Environment.GetCommandLineArgs().First();
+ }
+
+ string commandLineArgsString;
+
+ if (startupOptions.ContainsOption("-restartargs"))
+ {
+ commandLineArgsString = startupOptions.GetOption("-restartargs") ?? string.Empty;
+ }
+ else
+ {
+ commandLineArgsString = string.Join(" ",
+ Environment.GetCommandLineArgs()
+ .Skip(1)
+ .Select(NormalizeCommandLineArgument)
+ );
+ }
+
+ _logger.LogInformation("Executable: {0}", module);
+ _logger.LogInformation("Arguments: {0}", commandLineArgsString);
+
+ Process.Start(module, commandLineArgsString);
+ }
+
+ private static string NormalizeCommandLineArgument(string arg)
+ {
+ if (!arg.Contains(" ", StringComparison.OrdinalIgnoreCase))
+ {
+ return arg;
+ }
+
+ return "\"" + arg + "\"";
+ }
+ }
+}
diff --git a/Jellyfin.Server/Properties/AssemblyInfo.cs b/Jellyfin.Server/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000000..2959cdf1fe
--- /dev/null
+++ b/Jellyfin.Server/Properties/AssemblyInfo.cs
@@ -0,0 +1,21 @@
+using System.Reflection;
+using System.Resources;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("Jellyfin.Server")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("Jellyfin Project")]
+[assembly: AssemblyProduct("Jellyfin: The Free Software Media System")]
+[assembly: AssemblyCopyright("Copyright © 2019 Jellyfin Contributors. Code released under the GNU General Public License Version 2")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+[assembly: NeutralResourcesLanguage("en")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
diff --git a/Jellyfin.Server/Resources/Configuration/logging.json b/Jellyfin.Server/Resources/Configuration/logging.json
index 78f99b2ad9..d169912774 100644
--- a/Jellyfin.Server/Resources/Configuration/logging.json
+++ b/Jellyfin.Server/Resources/Configuration/logging.json
@@ -2,16 +2,25 @@
"Serilog": {
"MinimumLevel": "Information",
"WriteTo": [
- { "Name": "Console",
+ {
+ "Name": "Console",
"Args": {
"outputTemplate": "[{Timestamp:HH:mm:ss}] [{Level:u3}] {Message:lj}{NewLine}{Exception}"
}
},
- { "Name": "File",
+ {
+ "Name": "Async",
"Args": {
- "path": "%JELLYFIN_LOG_DIR%//log_.log",
- "rollingInterval": "Day",
- "outputTemplate": "[{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz}] [{Level:u3}] {Message}{NewLine}{Exception}"
+ "configure": [
+ {
+ "Name": "File",
+ "Args": {
+ "path": "%JELLYFIN_LOG_DIR%//log_.log",
+ "rollingInterval": "Day",
+ "outputTemplate": "[{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz}] [{Level:u3}] {Message}{NewLine}{Exception}"
+ }
+ }
+ ]
}
}
]
diff --git a/Jellyfin.Server/SocketSharp/HttpFile.cs b/Jellyfin.Server/SocketSharp/HttpFile.cs
index 4a798062dd..77ce035109 100644
--- a/Jellyfin.Server/SocketSharp/HttpFile.cs
+++ b/Jellyfin.Server/SocketSharp/HttpFile.cs
@@ -1,4 +1,4 @@
-using System.IO;
+using System.IO;
using MediaBrowser.Model.Services;
namespace Jellyfin.SocketSharp
diff --git a/Jellyfin.Server/SocketSharp/RequestMono.cs b/Jellyfin.Server/SocketSharp/RequestMono.cs
index 31f2894977..45cb323d28 100644
--- a/Jellyfin.Server/SocketSharp/RequestMono.cs
+++ b/Jellyfin.Server/SocketSharp/RequestMono.cs
@@ -1,4 +1,4 @@
-using System;
+using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
@@ -75,7 +75,7 @@ namespace Jellyfin.SocketSharp
//
// We use a substream, as in 2.x we will support large uploads streamed to disk,
//
- HttpPostedFile sub = new HttpPostedFile(e.Filename, e.ContentType, input, e.Start, e.Length);
+ var sub = new HttpPostedFile(e.Filename, e.ContentType, input, e.Start, e.Length);
files[e.Name] = sub;
}
}
@@ -97,12 +97,12 @@ namespace Jellyfin.SocketSharp
}
#if NET_4_0
- if (validateRequestNewMode && !checked_form) {
- // Setting this before calling the validator prevents
- // possible endless recursion
- checked_form = true;
- ValidateNameValueCollection ("Form", query_string_nvc, RequestValidationSource.Form);
- } else
+ if (validateRequestNewMode && !checked_form) {
+ // Setting this before calling the validator prevents
+ // possible endless recursion
+ checked_form = true;
+ ValidateNameValueCollection ("Form", query_string_nvc, RequestValidationSource.Form);
+ } else
#endif
if (validate_form && !checked_form)
{
@@ -113,21 +113,9 @@ namespace Jellyfin.SocketSharp
return form;
}
- public string Accept
- {
- get
- {
- return string.IsNullOrEmpty(request.Headers["Accept"]) ? null : request.Headers["Accept"];
- }
- }
+ public string Accept => string.IsNullOrEmpty(request.Headers["Accept"]) ? null : request.Headers["Accept"];
- public string Authorization
- {
- get
- {
- return string.IsNullOrEmpty(request.Headers["Authorization"]) ? null : request.Headers["Authorization"];
- }
- }
+ public string Authorization => string.IsNullOrEmpty(request.Headers["Authorization"]) ? null : request.Headers["Authorization"];
protected bool validate_cookies, validate_query_string, validate_form;
protected bool checked_cookies, checked_query_string, checked_form;
@@ -138,7 +126,7 @@ namespace Jellyfin.SocketSharp
if (v.Length > 20)
v = v.Substring(0, 16) + "...\"";
- string msg = String.Format("A potentially dangerous Request.{0} value was " +
+ string msg = string.Format("A potentially dangerous Request.{0} value was " +
"detected from the client ({1}={2}).", name, key, v);
throw new Exception(msg);
@@ -160,9 +148,7 @@ namespace Jellyfin.SocketSharp
internal static bool IsInvalidString(string val)
{
- int validationFailureIndex;
-
- return IsInvalidString(val, out validationFailureIndex);
+ return IsInvalidString(val, out var validationFailureIndex);
}
internal static bool IsInvalidString(string val, out int validationFailureIndex)
@@ -219,17 +205,17 @@ namespace Jellyfin.SocketSharp
async Task LoadWwwForm(WebROCollection form)
{
- using (Stream input = InputStream)
+ using (var input = InputStream)
{
using (var ms = new MemoryStream())
{
await input.CopyToAsync(ms).ConfigureAwait(false);
ms.Position = 0;
- using (StreamReader s = new StreamReader(ms, ContentEncoding))
+ using (var s = new StreamReader(ms, ContentEncoding))
{
- StringBuilder key = new StringBuilder();
- StringBuilder value = new StringBuilder();
+ var key = new StringBuilder();
+ var value = new StringBuilder();
int c;
while ((c = s.Read()) != -1)
@@ -281,7 +267,7 @@ namespace Jellyfin.SocketSharp
{
public override string ToString()
{
- StringBuilder result = new StringBuilder();
+ var result = new StringBuilder();
foreach (var pair in this)
{
if (result.Length > 0)
@@ -328,13 +314,13 @@ namespace Jellyfin.SocketSharp
public override int Read(byte[] buffer, int dest_offset, int count)
{
if (buffer == null)
- throw new ArgumentNullException("buffer");
+ throw new ArgumentNullException(nameof(buffer));
if (dest_offset < 0)
- throw new ArgumentOutOfRangeException("dest_offset", "< 0");
+ throw new ArgumentOutOfRangeException(nameof(dest_offset), "< 0");
if (count < 0)
- throw new ArgumentOutOfRangeException("count", "< 0");
+ throw new ArgumentOutOfRangeException(nameof(count), "< 0");
int len = buffer.Length;
if (dest_offset > len)
@@ -410,30 +396,17 @@ namespace Jellyfin.SocketSharp
throw new NotSupportedException();
}
- public override bool CanRead
- {
- get { return true; }
- }
- public override bool CanSeek
- {
- get { return true; }
- }
- public override bool CanWrite
- {
- get { return false; }
- }
+ public override bool CanRead => true;
- public override long Length
- {
- get { return end - offset; }
- }
+ public override bool CanSeek => true;
+
+ public override bool CanWrite => false;
+
+ public override long Length => end - offset;
public override long Position
{
- get
- {
- return position - offset;
- }
+ get => position - offset;
set
{
if (value > Length)
@@ -451,37 +424,13 @@ namespace Jellyfin.SocketSharp
this.stream = new ReadSubStream(base_stream, offset, length);
}
- public string ContentType
- {
- get
- {
- return content_type;
- }
- }
+ public string ContentType => content_type;
- public int ContentLength
- {
- get
- {
- return (int)stream.Length;
- }
- }
+ public int ContentLength => (int)stream.Length;
- public string FileName
- {
- get
- {
- return name;
- }
- }
+ public string FileName => name;
- public Stream InputStream
- {
- get
- {
- return stream;
- }
- }
+ public Stream InputStream => stream;
}
class Helpers
@@ -546,7 +495,7 @@ namespace Jellyfin.SocketSharp
const byte HYPHEN = (byte)'-', LF = (byte)'\n', CR = (byte)'\r';
- // See RFC 2046
+ // See RFC 2046
// In the case of multipart entities, in which one or more different
// sets of data are combined in a single body, a "multipart" media type
// field must appear in the entity's header. The body must then contain
@@ -764,7 +713,7 @@ namespace Jellyfin.SocketSharp
if (at_eof || ReadBoundary())
return null;
- Element elem = new Element();
+ var elem = new Element();
string header;
while ((header = ReadHeaders()) != null)
{
diff --git a/Jellyfin.Server/SocketSharp/SharpWebSocket.cs b/Jellyfin.Server/SocketSharp/SharpWebSocket.cs
index 77de50267c..d0dcd86ebf 100644
--- a/Jellyfin.Server/SocketSharp/SharpWebSocket.cs
+++ b/Jellyfin.Server/SocketSharp/SharpWebSocket.cs
@@ -1,7 +1,7 @@
using System;
+using System.Net.WebSockets;
using System.Threading;
using System.Threading.Tasks;
-using System.Net.WebSockets;
using Emby.Server.Implementations.Net;
using Microsoft.Extensions.Logging;
@@ -29,12 +29,12 @@ namespace Jellyfin.SocketSharp
{
if (socket == null)
{
- throw new ArgumentNullException("socket");
+ throw new ArgumentNullException(nameof(socket));
}
if (logger == null)
{
- throw new ArgumentNullException("logger");
+ throw new ArgumentNullException(nameof(logger));
}
_logger = logger;
@@ -85,13 +85,7 @@ namespace Jellyfin.SocketSharp
/// Gets or sets the state.
/// </summary>
/// <value>The state.</value>
- public WebSocketState State
- {
- get
- {
- return WebSocket.ReadyState;
- }
- }
+ public WebSocketState State => WebSocket.ReadyState;
/// <summary>
/// Sends the async.
diff --git a/Jellyfin.Server/SocketSharp/WebSocketSharpListener.cs b/Jellyfin.Server/SocketSharp/WebSocketSharpListener.cs
index c360a8fcea..ef75644d75 100644
--- a/Jellyfin.Server/SocketSharp/WebSocketSharpListener.cs
+++ b/Jellyfin.Server/SocketSharp/WebSocketSharpListener.cs
@@ -3,8 +3,8 @@ using System.Collections.Generic;
using System.Security.Cryptography.X509Certificates;
using System.Threading;
using System.Threading.Tasks;
-using Emby.Server.Implementations.Net;
using Emby.Server.Implementations.HttpServer;
+using Emby.Server.Implementations.Net;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Net;
using MediaBrowser.Model.Cryptography;
@@ -12,7 +12,6 @@ using MediaBrowser.Model.IO;
using MediaBrowser.Model.Net;
using MediaBrowser.Model.Services;
using MediaBrowser.Model.System;
-using MediaBrowser.Model.Text;
using Microsoft.Extensions.Logging;
using SocketHttpListener.Net;
@@ -25,7 +24,6 @@ namespace Jellyfin.SocketSharp
private readonly ILogger _logger;
private readonly X509Certificate _certificate;
private readonly IStreamHelper _streamHelper;
- private readonly ITextEncoding _textEncoding;
private readonly INetworkManager _networkManager;
private readonly ISocketFactory _socketFactory;
private readonly ICryptoProvider _cryptoProvider;
@@ -36,12 +34,13 @@ namespace Jellyfin.SocketSharp
private CancellationTokenSource _disposeCancellationTokenSource = new CancellationTokenSource();
private CancellationToken _disposeCancellationToken;
- public WebSocketSharpListener(ILogger logger, X509Certificate certificate, IStreamHelper streamHelper, ITextEncoding textEncoding, INetworkManager networkManager, ISocketFactory socketFactory, ICryptoProvider cryptoProvider, bool enableDualMode, IFileSystem fileSystem, IEnvironmentInfo environment)
+ public WebSocketSharpListener(ILogger logger, X509Certificate certificate, IStreamHelper streamHelper,
+ INetworkManager networkManager, ISocketFactory socketFactory, ICryptoProvider cryptoProvider,
+ bool enableDualMode, IFileSystem fileSystem, IEnvironmentInfo environment)
{
_logger = logger;
_certificate = certificate;
_streamHelper = streamHelper;
- _textEncoding = textEncoding;
_networkManager = networkManager;
_socketFactory = socketFactory;
_cryptoProvider = cryptoProvider;
@@ -62,7 +61,7 @@ namespace Jellyfin.SocketSharp
public void Start(IEnumerable<string> urlPrefixes)
{
if (_listener == null)
- _listener = new HttpListener(_logger, _cryptoProvider, _socketFactory, _networkManager, _textEncoding, _streamHelper, _fileSystem, _environment);
+ _listener = new HttpListener(_logger, _cryptoProvider, _socketFactory, _networkManager, _streamHelper, _fileSystem, _environment);
_listener.EnableDualMode = _enableDualMode;
@@ -202,6 +201,7 @@ namespace Jellyfin.SocketSharp
}
catch (ObjectDisposedException)
{
+ //TODO Investigate and properly fix.
}
catch (Exception ex)
{
diff --git a/Jellyfin.Server/SocketSharp/WebSocketSharpRequest.cs b/Jellyfin.Server/SocketSharp/WebSocketSharpRequest.cs
index 7c9dc8f88c..e38468388b 100644
--- a/Jellyfin.Server/SocketSharp/WebSocketSharpRequest.cs
+++ b/Jellyfin.Server/SocketSharp/WebSocketSharpRequest.cs
@@ -1,4 +1,4 @@
-using System;
+using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
@@ -39,88 +39,38 @@ namespace Jellyfin.SocketSharp
return string.IsNullOrEmpty(endHostUrl) ? null : endHostUrl.TrimEnd('/');
}
- public HttpListenerRequest HttpRequest
- {
- get { return request; }
- }
+ public HttpListenerRequest HttpRequest => request;
- public object OriginalRequest
- {
- get { return request; }
- }
+ public object OriginalRequest => request;
- public IResponse Response
- {
- get { return response; }
- }
+ public IResponse Response => response;
- public IHttpResponse HttpResponse
- {
- get { return response; }
- }
+ public IHttpResponse HttpResponse => response;
public string OperationName { get; set; }
public object Dto { get; set; }
- public string RawUrl
- {
- get { return request.RawUrl; }
- }
+ public string RawUrl => request.RawUrl;
- public string AbsoluteUri
- {
- get { return request.Url.AbsoluteUri.TrimEnd('/'); }
- }
+ public string AbsoluteUri => request.Url.AbsoluteUri.TrimEnd('/');
- public string UserHostAddress
- {
- get { return request.UserHostAddress; }
- }
+ public string UserHostAddress => request.UserHostAddress;
- public string XForwardedFor
- {
- get
- {
- return String.IsNullOrEmpty(request.Headers["X-Forwarded-For"]) ? null : request.Headers["X-Forwarded-For"];
- }
- }
+ public string XForwardedFor => string.IsNullOrEmpty(request.Headers["X-Forwarded-For"]) ? null : request.Headers["X-Forwarded-For"];
- public int? XForwardedPort
- {
- get
- {
- return string.IsNullOrEmpty(request.Headers["X-Forwarded-Port"]) ? (int?)null : int.Parse(request.Headers["X-Forwarded-Port"]);
- }
- }
+ public int? XForwardedPort => string.IsNullOrEmpty(request.Headers["X-Forwarded-Port"]) ? (int?)null : int.Parse(request.Headers["X-Forwarded-Port"]);
- public string XForwardedProtocol
- {
- get
- {
- return string.IsNullOrEmpty(request.Headers["X-Forwarded-Proto"]) ? null : request.Headers["X-Forwarded-Proto"];
- }
- }
+ public string XForwardedProtocol => string.IsNullOrEmpty(request.Headers["X-Forwarded-Proto"]) ? null : request.Headers["X-Forwarded-Proto"];
- public string XRealIp
- {
- get
- {
- return String.IsNullOrEmpty(request.Headers["X-Real-IP"]) ? null : request.Headers["X-Real-IP"];
- }
- }
+ public string XRealIp => string.IsNullOrEmpty(request.Headers["X-Real-IP"]) ? null : request.Headers["X-Real-IP"];
private string remoteIp;
- public string RemoteIp
- {
- get
- {
- return remoteIp ??
- (remoteIp = (CheckBadChars(XForwardedFor)) ??
- (NormalizeIp(CheckBadChars(XRealIp)) ??
- (request.RemoteEndPoint != null ? NormalizeIp(request.RemoteEndPoint.Address.ToString()) : null)));
- }
- }
+ public string RemoteIp =>
+ remoteIp ??
+ (remoteIp = (CheckBadChars(XForwardedFor)) ??
+ (NormalizeIp(CheckBadChars(XRealIp)) ??
+ (request.RemoteEndPoint != null ? NormalizeIp(request.RemoteEndPoint.Address.ToString()) : null)));
private static readonly char[] HttpTrimCharacters = new char[] { (char)0x09, (char)0xA, (char)0xB, (char)0xC, (char)0xD, (char)0x20 };
@@ -215,34 +165,20 @@ namespace Jellyfin.SocketSharp
return ip;
}
- public bool IsSecureConnection
- {
- get { return request.IsSecureConnection || XForwardedProtocol == "https"; }
- }
+ public bool IsSecureConnection => request.IsSecureConnection || XForwardedProtocol == "https";
- public string[] AcceptTypes
- {
- get { return request.AcceptTypes; }
- }
+ public string[] AcceptTypes => request.AcceptTypes;
private Dictionary<string, object> items;
- public Dictionary<string, object> Items
- {
- get { return items ?? (items = new Dictionary<string, object>()); }
- }
+ public Dictionary<string, object> Items => items ?? (items = new Dictionary<string, object>());
private string responseContentType;
public string ResponseContentType
{
- get
- {
- return responseContentType
- ?? (responseContentType = GetResponseContentType(this));
- }
- set
- {
- this.responseContentType = value;
- }
+ get =>
+ responseContentType
+ ?? (responseContentType = GetResponseContentType(this));
+ set => this.responseContentType = value;
}
public const string FormUrlEncoded = "application/x-www-form-urlencoded";
@@ -425,7 +361,7 @@ namespace Jellyfin.SocketSharp
cookies = new Dictionary<string, System.Net.Cookie>();
foreach (var cookie in this.request.Cookies)
{
- var httpCookie = (System.Net.Cookie) cookie;
+ var httpCookie = (System.Net.Cookie)cookie;
cookies[httpCookie.Name] = new System.Net.Cookie(httpCookie.Name, httpCookie.Value, httpCookie.Path, httpCookie.Domain);
}
}
@@ -434,58 +370,32 @@ namespace Jellyfin.SocketSharp
}
}
- public string UserAgent
- {
- get { return request.UserAgent; }
- }
+ public string UserAgent => request.UserAgent;
- public QueryParamCollection Headers
- {
- get { return request.Headers; }
- }
+ public QueryParamCollection Headers => request.Headers;
private QueryParamCollection queryString;
- public QueryParamCollection QueryString
- {
- get { return queryString ?? (queryString = MyHttpUtility.ParseQueryString(request.Url.Query)); }
- }
+ public QueryParamCollection QueryString => queryString ?? (queryString = MyHttpUtility.ParseQueryString(request.Url.Query));
- public bool IsLocal
- {
- get { return request.IsLocal; }
- }
+ public bool IsLocal => request.IsLocal;
private string httpMethod;
- public string HttpMethod
- {
- get
- {
- return httpMethod
- ?? (httpMethod = request.HttpMethod);
- }
- }
+ public string HttpMethod =>
+ httpMethod
+ ?? (httpMethod = request.HttpMethod);
- public string Verb
- {
- get { return HttpMethod; }
- }
+ public string Verb => HttpMethod;
- public string ContentType
- {
- get { return request.ContentType; }
- }
+ public string ContentType => request.ContentType;
public Encoding contentEncoding;
public Encoding ContentEncoding
{
- get { return contentEncoding ?? request.ContentEncoding; }
- set { contentEncoding = value; }
+ get => contentEncoding ?? request.ContentEncoding;
+ set => contentEncoding = value;
}
- public Uri UrlReferrer
- {
- get { return request.UrlReferrer; }
- }
+ public Uri UrlReferrer => request.UrlReferrer;
public static Encoding GetEncoding(string contentTypeHeader)
{
@@ -501,15 +411,9 @@ namespace Jellyfin.SocketSharp
}
}
- public Stream InputStream
- {
- get { return request.InputStream; }
- }
+ public Stream InputStream => request.InputStream;
- public long ContentLength
- {
- get { return request.ContentLength64; }
- }
+ public long ContentLength => request.ContentLength64;
private IHttpFile[] httpFiles;
public IHttpFile[] Files
diff --git a/Jellyfin.Server/SocketSharp/WebSocketSharpResponse.cs b/Jellyfin.Server/SocketSharp/WebSocketSharpResponse.cs
index c7437c8254..21bfac55da 100644
--- a/Jellyfin.Server/SocketSharp/WebSocketSharpResponse.cs
+++ b/Jellyfin.Server/SocketSharp/WebSocketSharpResponse.cs
@@ -1,4 +1,4 @@
-using System;
+using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
@@ -31,27 +31,24 @@ namespace Jellyfin.SocketSharp
public IRequest Request { get; private set; }
public Dictionary<string, object> Items { get; private set; }
- public object OriginalResponse
- {
- get { return _response; }
- }
+ public object OriginalResponse => _response;
public int StatusCode
{
- get { return this._response.StatusCode; }
- set { this._response.StatusCode = value; }
+ get => this._response.StatusCode;
+ set => this._response.StatusCode = value;
}
public string StatusDescription
{
- get { return this._response.StatusDescription; }
- set { this._response.StatusDescription = value; }
+ get => this._response.StatusDescription;
+ set => this._response.StatusDescription = value;
}
public string ContentType
{
- get { return _response.ContentType; }
- set { _response.ContentType = value; }
+ get => _response.ContentType;
+ set => _response.ContentType = value;
}
//public ICookies Cookies { get; set; }
@@ -67,13 +64,7 @@ namespace Jellyfin.SocketSharp
_response.AddHeader(name, value);
}
- public QueryParamCollection Headers
- {
- get
- {
- return _response.Headers;
- }
- }
+ public QueryParamCollection Headers => _response.Headers;
public string GetHeader(string name)
{
@@ -85,10 +76,7 @@ namespace Jellyfin.SocketSharp
_response.Redirect(url);
}
- public Stream OutputStream
- {
- get { return _response.OutputStream; }
- }
+ public Stream OutputStream => _response.OutputStream;
public void Close()
{
@@ -179,8 +167,8 @@ namespace Jellyfin.SocketSharp
public bool SendChunked
{
- get { return _response.SendChunked; }
- set { _response.SendChunked = value; }
+ get => _response.SendChunked;
+ set => _response.SendChunked = value;
}
public bool KeepAlive { get; set; }