From 31b01cbb5645cdc71791c85f2607aafbc6568dbc Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Fri, 22 Sep 2017 16:33:01 -0400 Subject: add fixes for dng images --- .../HttpServer/HttpResultFactory.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'Emby.Server.Implementations/HttpServer') diff --git a/Emby.Server.Implementations/HttpServer/HttpResultFactory.cs b/Emby.Server.Implementations/HttpServer/HttpResultFactory.cs index f5a1fe246..3e0565343 100644 --- a/Emby.Server.Implementations/HttpServer/HttpResultFactory.cs +++ b/Emby.Server.Implementations/HttpServer/HttpResultFactory.cs @@ -360,7 +360,7 @@ namespace Emby.Server.Implementations.HttpServer if (IsNotModified(requestContext, cacheKey, lastDateModified, cacheDuration)) { AddAgeHeader(responseHeaders, lastDateModified); - AddExpiresHeader(responseHeaders, cacheKeyString, cacheDuration, noCache); + AddExpiresHeader(responseHeaders, cacheKeyString, cacheDuration); var result = new HttpResult(new byte[] { }, contentType ?? "text/html", HttpStatusCode.NotModified); @@ -370,7 +370,7 @@ namespace Emby.Server.Implementations.HttpServer } } - AddCachingHeaders(responseHeaders, cacheKeyString, lastDateModified, cacheDuration, noCache); + AddCachingHeaders(responseHeaders, cacheKeyString, lastDateModified, cacheDuration); return null; } @@ -555,7 +555,7 @@ namespace Emby.Server.Implementations.HttpServer /// /// Adds the caching responseHeaders. /// - private void AddCachingHeaders(IDictionary responseHeaders, string cacheKey, DateTime? lastDateModified, TimeSpan? cacheDuration, bool noCache) + private void AddCachingHeaders(IDictionary responseHeaders, string cacheKey, DateTime? lastDateModified, TimeSpan? cacheDuration) { // Don't specify both last modified and Etag, unless caching unconditionally. They are redundant // https://developers.google.com/speed/docs/best-practices/caching#LeverageBrowserCaching @@ -565,11 +565,11 @@ namespace Emby.Server.Implementations.HttpServer responseHeaders["Last-Modified"] = lastDateModified.Value.ToString("r"); } - if (!noCache && cacheDuration.HasValue) + if (cacheDuration.HasValue) { responseHeaders["Cache-Control"] = "public, max-age=" + Convert.ToInt32(cacheDuration.Value.TotalSeconds); } - else if (!noCache && !string.IsNullOrEmpty(cacheKey)) + else if (!string.IsNullOrEmpty(cacheKey)) { responseHeaders["Cache-Control"] = "public"; } @@ -579,15 +579,15 @@ namespace Emby.Server.Implementations.HttpServer responseHeaders["pragma"] = "no-cache, no-store, must-revalidate"; } - AddExpiresHeader(responseHeaders, cacheKey, cacheDuration, noCache); + AddExpiresHeader(responseHeaders, cacheKey, cacheDuration); } /// /// Adds the expires header. /// - private void AddExpiresHeader(IDictionary responseHeaders, string cacheKey, TimeSpan? cacheDuration, bool noCache) + private void AddExpiresHeader(IDictionary responseHeaders, string cacheKey, TimeSpan? cacheDuration) { - if (!noCache && cacheDuration.HasValue) + if (cacheDuration.HasValue) { responseHeaders["Expires"] = DateTime.UtcNow.Add(cacheDuration.Value).ToString("r"); } -- cgit v1.2.3 From 39394e74c70f0b8fa9bd4415f6213edbd5ba04fd Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sat, 23 Sep 2017 21:03:46 -0400 Subject: fix dlna direct play on samsung tv's --- Emby.Server.Implementations/ApplicationHost.cs | 41 +++++++++++++++------- .../HttpServer/HttpResultFactory.cs | 2 +- .../Configuration/EncodingOptions.cs | 3 +- MediaBrowser.Server.Mono/MonoAppHost.cs | 2 +- 4 files changed, 33 insertions(+), 15 deletions(-) (limited to 'Emby.Server.Implementations/HttpServer') diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index ba43c7f35..894d91f71 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -2211,19 +2211,36 @@ namespace Emby.Server.Implementations TimeSpan.FromHours(12) : TimeSpan.FromMinutes(5); - var result = await new GithubUpdater(HttpClient, JsonSerializer).CheckForUpdateResult("MediaBrowser", - "Emby", - ApplicationVersion, - updateLevel, - ReleaseAssetFilename, - "MBServer", - UpdateTargetFileName, - cacheLength, - cancellationToken).ConfigureAwait(false); - - HasUpdateAvailable = result.IsUpdateAvailable; + try + { + var result = await new GithubUpdater(HttpClient, JsonSerializer).CheckForUpdateResult("MediaBrowser", + "Emby", + ApplicationVersion, + updateLevel, + ReleaseAssetFilename, + "MBServer", + UpdateTargetFileName, + cacheLength, + cancellationToken).ConfigureAwait(false); - return result; + HasUpdateAvailable = result.IsUpdateAvailable; + + return result; + } + catch (HttpException ex) + { + // users are overreacting to this occasionally failing + if (ex.StatusCode.HasValue && ex.StatusCode.Value == HttpStatusCode.Forbidden) + { + HasUpdateAvailable = false; + return new CheckForUpdateResult + { + IsUpdateAvailable = false + }; + } + + throw; + } } protected virtual string UpdateTargetFileName diff --git a/Emby.Server.Implementations/HttpServer/HttpResultFactory.cs b/Emby.Server.Implementations/HttpServer/HttpResultFactory.cs index 3e0565343..b06a6a887 100644 --- a/Emby.Server.Implementations/HttpServer/HttpResultFactory.cs +++ b/Emby.Server.Implementations/HttpServer/HttpResultFactory.cs @@ -533,7 +533,7 @@ namespace Emby.Server.Implementations.HttpServer { stream.Dispose(); - return GetHttpResult(new byte[] { }, contentType, true); + return GetHttpResult(new byte[] { }, contentType, true, responseHeaders); } var hasHeaders = new StreamWriter(stream, contentType, _logger) diff --git a/MediaBrowser.Model/Configuration/EncodingOptions.cs b/MediaBrowser.Model/Configuration/EncodingOptions.cs index a143bb9e3..fbc5e1b37 100644 --- a/MediaBrowser.Model/Configuration/EncodingOptions.cs +++ b/MediaBrowser.Model/Configuration/EncodingOptions.cs @@ -25,7 +25,8 @@ namespace MediaBrowser.Model.Configuration EnableThrottling = true; ThrottleDelaySeconds = 180; EncodingThreadCount = -1; - VaapiDevice = "/dev/dri/card0"; + // This is a DRM device that is almost guaranteed to be there on every intel platform, plus it's the default one in ffmpeg if you don't specify anything + VaapiDevice = "/dev/dri/renderD128"; H264Crf = 23; EnableHardwareEncoding = true; EnableSubtitleExtraction = true; diff --git a/MediaBrowser.Server.Mono/MonoAppHost.cs b/MediaBrowser.Server.Mono/MonoAppHost.cs index ded7bb5f3..fe684d928 100644 --- a/MediaBrowser.Server.Mono/MonoAppHost.cs +++ b/MediaBrowser.Server.Mono/MonoAppHost.cs @@ -26,7 +26,7 @@ namespace MediaBrowser.Server.Mono get { // A restart script must be provided - return StartupOptions.ContainsOption("-restartpath"); + return false; } } -- cgit v1.2.3 From 768f20b1bbc16c9f0eb013a486d472dc7d2684a2 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 24 Sep 2017 16:24:12 -0400 Subject: update response headers for HEAD requests --- Emby.Server.Implementations/HttpServer/HttpListenerHost.cs | 8 +++++++- Emby.Server.Implementations/HttpServer/HttpResultFactory.cs | 13 ++----------- SharedVersion.cs | 2 +- 3 files changed, 10 insertions(+), 13 deletions(-) (limited to 'Emby.Server.Implementations/HttpServer') diff --git a/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs b/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs index 86df798d0..0e68389da 100644 --- a/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs +++ b/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs @@ -579,7 +579,13 @@ namespace Emby.Server.Implementations.HttpServer catch (Exception ex) { - ErrorHandler(ex, httpReq, !string.Equals(ex.GetType().Name, "SocketException", StringComparison.OrdinalIgnoreCase)); + var logException = !string.Equals(ex.GetType().Name, "SocketException", StringComparison.OrdinalIgnoreCase); + +#if DEBUG + logException = true; +#endif + + ErrorHandler(ex, httpReq, logException); } finally { diff --git a/Emby.Server.Implementations/HttpServer/HttpResultFactory.cs b/Emby.Server.Implementations/HttpServer/HttpResultFactory.cs index b06a6a887..a70aad14e 100644 --- a/Emby.Server.Implementations/HttpServer/HttpResultFactory.cs +++ b/Emby.Server.Implementations/HttpServer/HttpResultFactory.cs @@ -424,16 +424,6 @@ namespace Emby.Server.Implementations.HttpServer options.ResponseHeaders = options.ResponseHeaders ?? new Dictionary(StringComparer.OrdinalIgnoreCase); - if (!options.ResponseHeaders.ContainsKey("Content-Disposition")) - { - // Quotes are valid in linux. They'll possibly cause issues here - var filename = (Path.GetFileName(path) ?? string.Empty).Replace("\"", string.Empty); - if (!string.IsNullOrWhiteSpace(filename)) - { - options.ResponseHeaders["Content-Disposition"] = "inline; filename=\"" + filename + "\""; - } - } - return GetStaticResult(requestContext, options); } @@ -490,7 +480,8 @@ namespace Emby.Server.Implementations.HttpServer return result; } - var isHeadRequest = options.IsHeadRequest; + // TODO: We don't really need the option value + var isHeadRequest = options.IsHeadRequest || string.Equals(requestContext.Verb, "HEAD", StringComparison.OrdinalIgnoreCase); var factoryFn = options.ContentFactory; var responseHeaders = options.ResponseHeaders; diff --git a/SharedVersion.cs b/SharedVersion.cs index 82a72685b..1093bcd4c 100644 --- a/SharedVersion.cs +++ b/SharedVersion.cs @@ -1,3 +1,3 @@ using System.Reflection; -[assembly: AssemblyVersion("3.2.32.4")] +[assembly: AssemblyVersion("3.2.32.5")] -- cgit v1.2.3 From a0d82a02c8059dbacacac727d334b3d39c052a48 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Tue, 26 Sep 2017 13:09:42 -0400 Subject: update param encoding --- .../Emby.Server.Implementations.csproj | 2 - .../HttpServer/HttpListenerHost.cs | 6 ++ .../TunerHosts/HdHomerun/HdHomerunHttpStream.cs | 5 +- .../LiveTv/TunerHosts/MulticastStream.cs | 81 ---------------------- .../LiveTv/TunerHosts/QueueStream.cs | 45 ------------ MediaBrowser.Model/Dlna/StreamInfo.cs | 4 +- SharedVersion.cs | 2 +- 7 files changed, 13 insertions(+), 132 deletions(-) delete mode 100644 Emby.Server.Implementations/LiveTv/TunerHosts/MulticastStream.cs delete mode 100644 Emby.Server.Implementations/LiveTv/TunerHosts/QueueStream.cs (limited to 'Emby.Server.Implementations/HttpServer') diff --git a/Emby.Server.Implementations/Emby.Server.Implementations.csproj b/Emby.Server.Implementations/Emby.Server.Implementations.csproj index 41a62a417..2a74817c2 100644 --- a/Emby.Server.Implementations/Emby.Server.Implementations.csproj +++ b/Emby.Server.Implementations/Emby.Server.Implementations.csproj @@ -427,8 +427,6 @@ - - diff --git a/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs b/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs index 0e68389da..031d1d90b 100644 --- a/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs +++ b/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs @@ -731,6 +731,12 @@ namespace Emby.Server.Implementations.HttpServer public object DeserializeJson(Type type, Stream stream) { + //using (var reader = new StreamReader(stream)) + //{ + // var json = reader.ReadToEnd(); + // Logger.Info(json); + // return _jsonSerializer.DeserializeFromString(json, type); + //} return _jsonSerializer.DeserializeFromStream(stream, type); } diff --git a/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunHttpStream.cs b/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunHttpStream.cs index 17b3713c4..0ae7098b1 100644 --- a/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunHttpStream.cs +++ b/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunHttpStream.cs @@ -39,7 +39,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun _tempFilePath = Path.Combine(appPaths.TranscodingTempPath, UniqueId + ".ts"); } - protected override async Task OpenInternal(CancellationToken openCancellationToken) + protected override Task OpenInternal(CancellationToken openCancellationToken) { _liveStreamCancellationTokenSource.Token.ThrowIfCancellationRequested(); @@ -66,7 +66,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun //OpenedMediaSource.SupportsDirectStream = true; //OpenedMediaSource.SupportsTranscoding = true; - await taskCompletionSource.Task.ConfigureAwait(false); + return taskCompletionSource.Task; //await Task.Delay(5000).ConfigureAwait(false); } @@ -160,6 +160,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun while (!cancellationToken.IsCancellationRequested) { StreamHelper.CopyTo(inputStream, stream, 81920, cancellationToken); + //await inputStream.CopyToAsync(stream, 81920, cancellationToken).ConfigureAwait(false); //var position = fs.Position; //_logger.Debug("Streamed {0} bytes to position {1} from file {2}", bytesRead, position, path); diff --git a/Emby.Server.Implementations/LiveTv/TunerHosts/MulticastStream.cs b/Emby.Server.Implementations/LiveTv/TunerHosts/MulticastStream.cs deleted file mode 100644 index 45a0c348e..000000000 --- a/Emby.Server.Implementations/LiveTv/TunerHosts/MulticastStream.cs +++ /dev/null @@ -1,81 +0,0 @@ -using System; -using System.Collections.Concurrent; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; -using System.Threading; -using System.Threading.Tasks; -using MediaBrowser.Model.Logging; -using MediaBrowser.Model.Net; - -namespace Emby.Server.Implementations.LiveTv.TunerHosts -{ - public class MulticastStream - { - private readonly ConcurrentDictionary _outputStreams = new ConcurrentDictionary(); - private const int BufferSize = 81920; - private readonly ILogger _logger; - - public MulticastStream(ILogger logger) - { - _logger = logger; - } - - public async Task CopyUntilCancelled(Stream source, Action onStarted, CancellationToken cancellationToken) - { - if (source == null) - { - throw new ArgumentNullException("source"); - } - - while (true) - { - cancellationToken.ThrowIfCancellationRequested(); - - byte[] buffer = new byte[BufferSize]; - - var bytesRead = source.Read(buffer, 0, buffer.Length); - - if (bytesRead > 0) - { - foreach (var stream in _outputStreams) - { - stream.Value.Queue(buffer, 0, bytesRead); - } - - if (onStarted != null) - { - var onStartedCopy = onStarted; - onStarted = null; - Task.Run(onStartedCopy); - } - } - - else - { - await Task.Delay(100).ConfigureAwait(false); - } - } - } - - public Task CopyToAsync(Stream stream, CancellationToken cancellationToken) - { - var queueStream = new QueueStream(stream, _logger); - - _outputStreams.TryAdd(queueStream.Id, queueStream); - - try - { - queueStream.Start(cancellationToken); - } - finally - { - _outputStreams.TryRemove(queueStream.Id, out queueStream); - GC.Collect(); - } - - return Task.FromResult(true); - } - } -} diff --git a/Emby.Server.Implementations/LiveTv/TunerHosts/QueueStream.cs b/Emby.Server.Implementations/LiveTv/TunerHosts/QueueStream.cs deleted file mode 100644 index 07a4daa87..000000000 --- a/Emby.Server.Implementations/LiveTv/TunerHosts/QueueStream.cs +++ /dev/null @@ -1,45 +0,0 @@ -using System; -using System.Collections.Concurrent; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; -using System.Threading; -using System.Threading.Tasks; -using MediaBrowser.Model.Logging; - -namespace Emby.Server.Implementations.LiveTv.TunerHosts -{ - public class QueueStream - { - private readonly Stream _outputStream; - private readonly BlockingCollection> _queue = new BlockingCollection>(); - - private readonly ILogger _logger; - public Guid Id = Guid.NewGuid(); - - public QueueStream(Stream outputStream, ILogger logger) - { - _outputStream = outputStream; - _logger = logger; - } - - public void Queue(byte[] bytes, int offset, int count) - { - _queue.Add(new Tuple(bytes, offset, count)); - } - - public void Start(CancellationToken cancellationToken) - { - while (true) - { - foreach (var result in _queue.GetConsumingEnumerable()) - { - cancellationToken.ThrowIfCancellationRequested(); - - _outputStream.Write(result.Item1, result.Item2, result.Item3); - } - } - } - } -} diff --git a/MediaBrowser.Model/Dlna/StreamInfo.cs b/MediaBrowser.Model/Dlna/StreamInfo.cs index fe5aaa739..2019acd0d 100644 --- a/MediaBrowser.Model/Dlna/StreamInfo.cs +++ b/MediaBrowser.Model/Dlna/StreamInfo.cs @@ -169,7 +169,9 @@ namespace MediaBrowser.Model.Dlna continue; } - list.Add(string.Format("{0}={1}", pair.Name, pair.Value)); + var encodedValue = pair.Value.Replace(" ", "%20"); + + list.Add(string.Format("{0}={1}", pair.Name, encodedValue)); } string queryString = string.Join("&", list.ToArray(list.Count)); diff --git a/SharedVersion.cs b/SharedVersion.cs index 53f824397..f48c78f88 100644 --- a/SharedVersion.cs +++ b/SharedVersion.cs @@ -1,3 +1,3 @@ using System.Reflection; -[assembly: AssemblyVersion("3.2.32.7")] +[assembly: AssemblyVersion("3.2.32.8")] -- cgit v1.2.3 From 8d4602035f48e5d00d3145b3e7b6a7075d627b7f Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Thu, 28 Sep 2017 13:05:10 -0400 Subject: fix for missing response headers --- .../HttpServer/HttpResultFactory.cs | 43 ++++++++++------------ .../ImageEncoderHelper.cs | 1 - 2 files changed, 19 insertions(+), 25 deletions(-) (limited to 'Emby.Server.Implementations/HttpServer') diff --git a/Emby.Server.Implementations/HttpServer/HttpResultFactory.cs b/Emby.Server.Implementations/HttpServer/HttpResultFactory.cs index a70aad14e..86deccee1 100644 --- a/Emby.Server.Implementations/HttpServer/HttpResultFactory.cs +++ b/Emby.Server.Implementations/HttpServer/HttpResultFactory.cs @@ -142,8 +142,6 @@ namespace Emby.Server.Implementations.HttpServer throw new ArgumentNullException("result"); } - var optimizedResult = ToOptimizedResult(requestContext, result); - if (responseHeaders == null) { responseHeaders = new Dictionary(StringComparer.OrdinalIgnoreCase); @@ -154,15 +152,7 @@ namespace Emby.Server.Implementations.HttpServer responseHeaders["Expires"] = "-1"; } - // Apply headers - var hasHeaders = optimizedResult as IHasHeaders; - - if (hasHeaders != null) - { - AddResponseHeaders(hasHeaders, responseHeaders); - } - - return optimizedResult; + return ToOptimizedResultInternal(requestContext, result, responseHeaders); } public static string GetCompressionType(IRequest request) @@ -189,6 +179,11 @@ namespace Emby.Server.Implementations.HttpServer /// /// public object ToOptimizedResult(IRequest request, T dto) + { + return ToOptimizedResultInternal(request, dto, null); + } + + private object ToOptimizedResultInternal(IRequest request, T dto, IDictionary responseHeaders = null) { var contentType = request.ResponseContentType; @@ -197,27 +192,27 @@ namespace Emby.Server.Implementations.HttpServer case "application/xml": case "text/xml": case "text/xml; charset=utf-8": //"text/xml; charset=utf-8" also matches xml - return SerializeToXmlString(dto); + return GetHttpResult(SerializeToXmlString(dto), contentType, false, responseHeaders); case "application/json": case "text/json": - return _jsonSerializer.SerializeToString(dto); + return GetHttpResult(_jsonSerializer.SerializeToString(dto), contentType, false, responseHeaders); default: - { - var ms = new MemoryStream(); - var writerFn = RequestHelper.GetResponseWriter(HttpListenerHost.Instance, contentType); + { + var ms = new MemoryStream(); + var writerFn = RequestHelper.GetResponseWriter(HttpListenerHost.Instance, contentType); - writerFn(dto, ms); - - ms.Position = 0; + writerFn(dto, ms); - if (string.Equals(request.Verb, "head", StringComparison.OrdinalIgnoreCase)) - { - return GetHttpResult(new byte[] { }, contentType, true); - } + ms.Position = 0; - return GetHttpResult(ms, contentType, true); + if (string.Equals(request.Verb, "head", StringComparison.OrdinalIgnoreCase)) + { + return GetHttpResult(new byte[] { }, contentType, true, responseHeaders); } + + return GetHttpResult(ms, contentType, true, responseHeaders); + } } } diff --git a/MediaBrowser.ServerApplication/ImageEncoderHelper.cs b/MediaBrowser.ServerApplication/ImageEncoderHelper.cs index 0e99bbbad..c86e85785 100644 --- a/MediaBrowser.ServerApplication/ImageEncoderHelper.cs +++ b/MediaBrowser.ServerApplication/ImageEncoderHelper.cs @@ -1,7 +1,6 @@ using System; using Emby.Drawing; using Emby.Drawing.Skia; -using Emby.Server.Core; using Emby.Server.Implementations; using MediaBrowser.Common.Configuration; using MediaBrowser.Common.Net; -- cgit v1.2.3 From 878abbddda4da46811d8709ec90248b9c1b5f569 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Fri, 29 Sep 2017 15:17:54 -0400 Subject: fixes #1427 - [Feature Request]: Require Encryption --- Emby.Server.Implementations/ApplicationHost.cs | 4 ++-- .../EntryPoints/ExternalPortForwarding.cs | 2 +- .../HttpServer/HttpListenerHost.cs | 19 +++++++++++++++++++ .../Configuration/ServerConfiguration.cs | 2 ++ 4 files changed, 24 insertions(+), 3 deletions(-) (limited to 'Emby.Server.Implementations/HttpServer') diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index 699621043..57c509923 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -1931,13 +1931,13 @@ namespace Emby.Server.Implementations { get { - return SupportsHttps && ServerConfigurationManager.Configuration.EnableHttps; + return SupportsHttps && (ServerConfigurationManager.Configuration.EnableHttps || ServerConfigurationManager.Configuration.RequireHttps); } } public bool SupportsHttps { - get { return Certificate != null; } + get { return Certificate != null || ServerConfigurationManager.Configuration.IsBehindProxy; } } public async Task GetLocalApiUrl() diff --git a/Emby.Server.Implementations/EntryPoints/ExternalPortForwarding.cs b/Emby.Server.Implementations/EntryPoints/ExternalPortForwarding.cs index 9b434d606..2cef46839 100644 --- a/Emby.Server.Implementations/EntryPoints/ExternalPortForwarding.cs +++ b/Emby.Server.Implementations/EntryPoints/ExternalPortForwarding.cs @@ -48,7 +48,7 @@ namespace Emby.Server.Implementations.EntryPoints values.Add(config.PublicPort.ToString(CultureInfo.InvariantCulture)); values.Add(_appHost.HttpPort.ToString(CultureInfo.InvariantCulture)); values.Add(_appHost.HttpsPort.ToString(CultureInfo.InvariantCulture)); - values.Add(config.EnableHttps.ToString()); + values.Add((config.EnableHttps || config.RequireHttps).ToString()); values.Add(_appHost.EnableHttps.ToString()); return string.Join("|", values.ToArray(values.Count)); diff --git a/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs b/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs index 031d1d90b..acc247e45 100644 --- a/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs +++ b/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs @@ -423,6 +423,19 @@ namespace Emby.Server.Implementations.HttpServer return true; } + private bool ValidateSsl(string remoteIp) + { + if (_config.Configuration.RequireHttps && _appHost.EnableHttps) + { + if (!_networkManager.IsInLocalNetwork(remoteIp)) + { + return false; + } + } + + return true; + } + /// /// Overridable method that can be used to implement a custom hnandler /// @@ -453,6 +466,12 @@ namespace Emby.Server.Implementations.HttpServer return; } + if (!ValidateSsl(httpReq.RemoteIp)) + { + RedirectToUrl(httpRes, urlString.Replace("http://", "https://", StringComparison.OrdinalIgnoreCase)); + return; + } + if (string.Equals(httpReq.Verb, "OPTIONS", StringComparison.OrdinalIgnoreCase)) { httpRes.StatusCode = 200; diff --git a/MediaBrowser.Model/Configuration/ServerConfiguration.cs b/MediaBrowser.Model/Configuration/ServerConfiguration.cs index 7c7358845..f7fffbf79 100644 --- a/MediaBrowser.Model/Configuration/ServerConfiguration.cs +++ b/MediaBrowser.Model/Configuration/ServerConfiguration.cs @@ -181,6 +181,8 @@ namespace MediaBrowser.Model.Configuration public string[] CodecsUsed { get; set; } public bool EnableChannelView { get; set; } public bool EnableExternalContentInSuggestions { get; set; } + public bool RequireHttps { get; set; } + public bool IsBehindProxy { get; set; } public int ImageExtractionTimeoutMs { get; set; } -- cgit v1.2.3 From 5d583f42d4bc918256bcd50d26e555dcbd892e66 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sat, 30 Sep 2017 13:40:42 -0400 Subject: update https redirect --- .../HttpServer/HttpListenerHost.cs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'Emby.Server.Implementations/HttpServer') diff --git a/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs b/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs index acc247e45..737d4ceea 100644 --- a/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs +++ b/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs @@ -4,6 +4,7 @@ using MediaBrowser.Controller.Net; using MediaBrowser.Model.Logging; using System; using System.Collections.Generic; +using System.Globalization; using System.IO; using System.Linq; using System.Reflection; @@ -423,13 +424,16 @@ namespace Emby.Server.Implementations.HttpServer return true; } - private bool ValidateSsl(string remoteIp) + private bool ValidateSsl(string remoteIp, string urlString) { if (_config.Configuration.RequireHttps && _appHost.EnableHttps) { - if (!_networkManager.IsInLocalNetwork(remoteIp)) + if (urlString.IndexOf("https://", StringComparison.OrdinalIgnoreCase) == -1) { - return false; + if (!_networkManager.IsInLocalNetwork(remoteIp)) + { + return false; + } } } @@ -466,9 +470,13 @@ namespace Emby.Server.Implementations.HttpServer return; } - if (!ValidateSsl(httpReq.RemoteIp)) + if (!ValidateSsl(httpReq.RemoteIp, urlString)) { - RedirectToUrl(httpRes, urlString.Replace("http://", "https://", StringComparison.OrdinalIgnoreCase)); + var httpsUrl = urlString + .Replace("http://", "https://", StringComparison.OrdinalIgnoreCase) + .Replace(":" + _config.Configuration.PublicPort.ToString(CultureInfo.InvariantCulture), ":" + _config.Configuration.PublicHttpsPort.ToString(CultureInfo.InvariantCulture), StringComparison.OrdinalIgnoreCase); + + RedirectToUrl(httpRes, httpsUrl); return; } @@ -487,7 +495,7 @@ namespace Emby.Server.Implementations.HttpServer enableLog = EnableLogging(urlString, localPath); urlToLog = urlString; - logHeaders = enableLog && urlToLog.IndexOf("/videos/", StringComparison.OrdinalIgnoreCase) != -1; + logHeaders = enableLog && urlToLog.IndexOf("/videos/", StringComparison.OrdinalIgnoreCase) != -1; if (enableLog) { -- cgit v1.2.3