From bd2bec4d4aedb1e39082d51abd75797eaf42b28a Mon Sep 17 00:00:00 2001 From: SenorSmartyPants Date: Fri, 7 Jan 2022 16:29:22 -0600 Subject: [PATCH 1/3] Remove special HTTP HEAD processing removing this allows HTTP 206 Partial Content responses and lets some clients(popcorn hour namely) play videos from JF. --- Jellyfin.Api/Controllers/ImageController.cs | 6 ------ Jellyfin.Api/Helpers/FileStreamResponseHelpers.cs | 12 ------------ 2 files changed, 18 deletions(-) diff --git a/Jellyfin.Api/Controllers/ImageController.cs b/Jellyfin.Api/Controllers/ImageController.cs index 86933074d0..9ed9430cc1 100644 --- a/Jellyfin.Api/Controllers/ImageController.cs +++ b/Jellyfin.Api/Controllers/ImageController.cs @@ -2020,12 +2020,6 @@ namespace Jellyfin.Api.Controllers } } - // if the request is a head request, return a NoContent result with the same headers as it would with a GET request - if (isHeadRequest) - { - return NoContent(); - } - return PhysicalFile(imagePath, imageContentType ?? MediaTypeNames.Text.Plain); } } diff --git a/Jellyfin.Api/Helpers/FileStreamResponseHelpers.cs b/Jellyfin.Api/Helpers/FileStreamResponseHelpers.cs index 6385b62c96..639bbb82e3 100644 --- a/Jellyfin.Api/Helpers/FileStreamResponseHelpers.cs +++ b/Jellyfin.Api/Helpers/FileStreamResponseHelpers.cs @@ -45,12 +45,6 @@ namespace Jellyfin.Api.Helpers httpContext.Response.Headers[HeaderNames.AcceptRanges] = "none"; - if (isHeadRequest) - { - httpContext.Response.Headers[HeaderNames.ContentType] = contentType; - return new OkResult(); - } - return new FileStreamResult(await response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false), contentType); } @@ -70,12 +64,6 @@ namespace Jellyfin.Api.Helpers { httpContext.Response.ContentType = contentType; - // if the request is a head request, return an OkResult (200) with the same headers as it would with a GET request - if (isHeadRequest) - { - return new OkResult(); - } - return new PhysicalFileResult(path, contentType) { EnableRangeProcessing = true }; } From 3ea54a8009617998e7250a39e33a9da3440a9631 Mon Sep 17 00:00:00 2001 From: SenorSmartyPants Date: Fri, 7 Jan 2022 18:21:48 -0600 Subject: [PATCH 2/3] Remove isHeadRequest from GetStaticFile method signatures --- .../Controllers/DynamicHlsController.cs | 2 +- .../Controllers/HlsSegmentController.cs | 4 +- Jellyfin.Api/Controllers/ImageController.cs | 45 ++++++------------- Jellyfin.Api/Controllers/VideosController.cs | 3 +- Jellyfin.Api/Helpers/AudioHelper.cs | 3 +- .../Helpers/FileStreamResponseHelpers.cs | 6 --- 6 files changed, 19 insertions(+), 44 deletions(-) diff --git a/Jellyfin.Api/Controllers/DynamicHlsController.cs b/Jellyfin.Api/Controllers/DynamicHlsController.cs index 6ef3a2ff97..8e17de3b07 100644 --- a/Jellyfin.Api/Controllers/DynamicHlsController.cs +++ b/Jellyfin.Api/Controllers/DynamicHlsController.cs @@ -1954,7 +1954,7 @@ namespace Jellyfin.Api.Controllers return Task.CompletedTask; }); - return FileStreamResponseHelpers.GetStaticFileResult(segmentPath, MimeTypes.GetMimeType(segmentPath), false, HttpContext); + return FileStreamResponseHelpers.GetStaticFileResult(segmentPath, MimeTypes.GetMimeType(segmentPath), HttpContext); } private long GetEndPositionTicks(StreamState state, int requestedIndex) diff --git a/Jellyfin.Api/Controllers/HlsSegmentController.cs b/Jellyfin.Api/Controllers/HlsSegmentController.cs index 7325dca0ae..d76f485df7 100644 --- a/Jellyfin.Api/Controllers/HlsSegmentController.cs +++ b/Jellyfin.Api/Controllers/HlsSegmentController.cs @@ -69,7 +69,7 @@ namespace Jellyfin.Api.Controllers return BadRequest("Invalid segment."); } - return FileStreamResponseHelpers.GetStaticFileResult(file, MimeTypes.GetMimeType(file), false, HttpContext); + return FileStreamResponseHelpers.GetStaticFileResult(file, MimeTypes.GetMimeType(file), HttpContext); } /// @@ -186,7 +186,7 @@ namespace Jellyfin.Api.Controllers return Task.CompletedTask; }); - return FileStreamResponseHelpers.GetStaticFileResult(path, MimeTypes.GetMimeType(path), false, HttpContext); + return FileStreamResponseHelpers.GetStaticFileResult(path, MimeTypes.GetMimeType(path), HttpContext); } } } diff --git a/Jellyfin.Api/Controllers/ImageController.cs b/Jellyfin.Api/Controllers/ImageController.cs index 9ed9430cc1..e1193d17eb 100644 --- a/Jellyfin.Api/Controllers/ImageController.cs +++ b/Jellyfin.Api/Controllers/ImageController.cs @@ -559,8 +559,7 @@ namespace Jellyfin.Api.Controllers blur, backgroundColor, foregroundLayer, - item, - Request.Method.Equals(HttpMethods.Head, StringComparison.OrdinalIgnoreCase)) + item) .ConfigureAwait(false); } @@ -643,8 +642,7 @@ namespace Jellyfin.Api.Controllers blur, backgroundColor, foregroundLayer, - item, - Request.Method.Equals(HttpMethods.Head, StringComparison.OrdinalIgnoreCase)) + item) .ConfigureAwait(false); } @@ -727,8 +725,7 @@ namespace Jellyfin.Api.Controllers blur, backgroundColor, foregroundLayer, - item, - Request.Method.Equals(HttpMethods.Head, StringComparison.OrdinalIgnoreCase)) + item) .ConfigureAwait(false); } @@ -811,8 +808,7 @@ namespace Jellyfin.Api.Controllers blur, backgroundColor, foregroundLayer, - item, - Request.Method.Equals(HttpMethods.Head, StringComparison.OrdinalIgnoreCase)) + item) .ConfigureAwait(false); } @@ -895,8 +891,7 @@ namespace Jellyfin.Api.Controllers blur, backgroundColor, foregroundLayer, - item, - Request.Method.Equals(HttpMethods.Head, StringComparison.OrdinalIgnoreCase)) + item) .ConfigureAwait(false); } @@ -979,8 +974,7 @@ namespace Jellyfin.Api.Controllers blur, backgroundColor, foregroundLayer, - item, - Request.Method.Equals(HttpMethods.Head, StringComparison.OrdinalIgnoreCase)) + item) .ConfigureAwait(false); } @@ -1063,8 +1057,7 @@ namespace Jellyfin.Api.Controllers blur, backgroundColor, foregroundLayer, - item, - Request.Method.Equals(HttpMethods.Head, StringComparison.OrdinalIgnoreCase)) + item) .ConfigureAwait(false); } @@ -1147,8 +1140,7 @@ namespace Jellyfin.Api.Controllers blur, backgroundColor, foregroundLayer, - item, - Request.Method.Equals(HttpMethods.Head, StringComparison.OrdinalIgnoreCase)) + item) .ConfigureAwait(false); } @@ -1231,8 +1223,7 @@ namespace Jellyfin.Api.Controllers blur, backgroundColor, foregroundLayer, - item, - Request.Method.Equals(HttpMethods.Head, StringComparison.OrdinalIgnoreCase)) + item) .ConfigureAwait(false); } @@ -1315,8 +1306,7 @@ namespace Jellyfin.Api.Controllers blur, backgroundColor, foregroundLayer, - item, - Request.Method.Equals(HttpMethods.Head, StringComparison.OrdinalIgnoreCase)) + item) .ConfigureAwait(false); } @@ -1399,8 +1389,7 @@ namespace Jellyfin.Api.Controllers blur, backgroundColor, foregroundLayer, - item, - Request.Method.Equals(HttpMethods.Head, StringComparison.OrdinalIgnoreCase)) + item) .ConfigureAwait(false); } @@ -1483,8 +1472,7 @@ namespace Jellyfin.Api.Controllers blur, backgroundColor, foregroundLayer, - item, - Request.Method.Equals(HttpMethods.Head, StringComparison.OrdinalIgnoreCase)) + item) .ConfigureAwait(false); } @@ -1585,7 +1573,6 @@ namespace Jellyfin.Api.Controllers backgroundColor, foregroundLayer, null, - Request.Method.Equals(HttpMethods.Head, StringComparison.OrdinalIgnoreCase), info) .ConfigureAwait(false); } @@ -1687,7 +1674,6 @@ namespace Jellyfin.Api.Controllers backgroundColor, foregroundLayer, null, - Request.Method.Equals(HttpMethods.Head, StringComparison.OrdinalIgnoreCase), info) .ConfigureAwait(false); } @@ -1772,7 +1758,6 @@ namespace Jellyfin.Api.Controllers string? backgroundColor, string? foregroundLayer, BaseItem? item, - bool isHeadRequest, ItemImageInfo? imageInfo = null) { if (percentPlayed.HasValue) @@ -1843,8 +1828,7 @@ namespace Jellyfin.Api.Controllers imageInfo, outputFormats, cacheDuration, - responseHeaders, - isHeadRequest).ConfigureAwait(false); + responseHeaders).ConfigureAwait(false); } private ImageFormat[] GetOutputFormats(ImageFormat? format) @@ -1941,8 +1925,7 @@ namespace Jellyfin.Api.Controllers ItemImageInfo imageInfo, IReadOnlyCollection supportedFormats, TimeSpan? cacheDuration, - IDictionary headers, - bool isHeadRequest) + IDictionary headers) { if (!imageInfo.IsLocalFile && item != null) { diff --git a/Jellyfin.Api/Controllers/VideosController.cs b/Jellyfin.Api/Controllers/VideosController.cs index 3c079a71dc..47eacd36b9 100644 --- a/Jellyfin.Api/Controllers/VideosController.cs +++ b/Jellyfin.Api/Controllers/VideosController.cs @@ -470,7 +470,7 @@ namespace Jellyfin.Api.Controllers StreamingHelpers.AddDlnaHeaders(state, Response.Headers, true, state.Request.StartTimeTicks, Request, _dlnaManager); var httpClient = _httpClientFactory.CreateClient(NamedClient.Default); - return await FileStreamResponseHelpers.GetStaticRemoteStreamResult(state, isHeadRequest, httpClient, HttpContext).ConfigureAwait(false); + return await FileStreamResponseHelpers.GetStaticRemoteStreamResult(state, httpClient, HttpContext).ConfigureAwait(false); } if (@static.HasValue && @static.Value && state.InputProtocol != MediaProtocol.File) @@ -500,7 +500,6 @@ namespace Jellyfin.Api.Controllers return FileStreamResponseHelpers.GetStaticFileResult( state.MediaPath, contentType, - isHeadRequest, HttpContext); } diff --git a/Jellyfin.Api/Helpers/AudioHelper.cs b/Jellyfin.Api/Helpers/AudioHelper.cs index bec961dadb..b831e81306 100644 --- a/Jellyfin.Api/Helpers/AudioHelper.cs +++ b/Jellyfin.Api/Helpers/AudioHelper.cs @@ -138,7 +138,7 @@ namespace Jellyfin.Api.Helpers StreamingHelpers.AddDlnaHeaders(state, _httpContextAccessor.HttpContext.Response.Headers, true, streamingRequest.StartTimeTicks, _httpContextAccessor.HttpContext.Request, _dlnaManager); var httpClient = _httpClientFactory.CreateClient(NamedClient.Default); - return await FileStreamResponseHelpers.GetStaticRemoteStreamResult(state, isHeadRequest, httpClient, _httpContextAccessor.HttpContext).ConfigureAwait(false); + return await FileStreamResponseHelpers.GetStaticRemoteStreamResult(state, httpClient, _httpContextAccessor.HttpContext).ConfigureAwait(false); } if (streamingRequest.Static && state.InputProtocol != MediaProtocol.File) @@ -168,7 +168,6 @@ namespace Jellyfin.Api.Helpers return FileStreamResponseHelpers.GetStaticFileResult( state.MediaPath, contentType, - isHeadRequest, _httpContextAccessor.HttpContext); } diff --git a/Jellyfin.Api/Helpers/FileStreamResponseHelpers.cs b/Jellyfin.Api/Helpers/FileStreamResponseHelpers.cs index 639bbb82e3..c99b911bbd 100644 --- a/Jellyfin.Api/Helpers/FileStreamResponseHelpers.cs +++ b/Jellyfin.Api/Helpers/FileStreamResponseHelpers.cs @@ -22,14 +22,12 @@ namespace Jellyfin.Api.Helpers /// Returns a static file from a remote source. /// /// The current . - /// Whether the current request is a HTTP HEAD request so only the headers get returned. /// The making the remote request. /// The current http context. /// A cancellation token that can be used to cancel the operation. /// A containing the API response. public static async Task GetStaticRemoteStreamResult( StreamState state, - bool isHeadRequest, HttpClient httpClient, HttpContext httpContext, CancellationToken cancellationToken = default) @@ -53,17 +51,13 @@ namespace Jellyfin.Api.Helpers /// /// The path to the file. /// The content type of the file. - /// Whether the current request is a HTTP HEAD request so only the headers get returned. /// The current http context. /// An the file. public static ActionResult GetStaticFileResult( string path, string contentType, - bool isHeadRequest, HttpContext httpContext) { - httpContext.Response.ContentType = contentType; - return new PhysicalFileResult(path, contentType) { EnableRangeProcessing = true }; } From d5e7e754215d5e2d83e53e8a7898c01195c0d5b3 Mon Sep 17 00:00:00 2001 From: SenorSmartyPants Date: Sat, 8 Jan 2022 19:53:53 -0600 Subject: [PATCH 3/3] Remove unused httpContext parameter --- Jellyfin.Api/Controllers/DynamicHlsController.cs | 2 +- Jellyfin.Api/Controllers/HlsSegmentController.cs | 4 ++-- Jellyfin.Api/Controllers/VideosController.cs | 3 +-- Jellyfin.Api/Helpers/AudioHelper.cs | 3 +-- Jellyfin.Api/Helpers/FileStreamResponseHelpers.cs | 4 +--- 5 files changed, 6 insertions(+), 10 deletions(-) diff --git a/Jellyfin.Api/Controllers/DynamicHlsController.cs b/Jellyfin.Api/Controllers/DynamicHlsController.cs index 8e17de3b07..f6d8347a4d 100644 --- a/Jellyfin.Api/Controllers/DynamicHlsController.cs +++ b/Jellyfin.Api/Controllers/DynamicHlsController.cs @@ -1954,7 +1954,7 @@ namespace Jellyfin.Api.Controllers return Task.CompletedTask; }); - return FileStreamResponseHelpers.GetStaticFileResult(segmentPath, MimeTypes.GetMimeType(segmentPath), HttpContext); + return FileStreamResponseHelpers.GetStaticFileResult(segmentPath, MimeTypes.GetMimeType(segmentPath)); } private long GetEndPositionTicks(StreamState state, int requestedIndex) diff --git a/Jellyfin.Api/Controllers/HlsSegmentController.cs b/Jellyfin.Api/Controllers/HlsSegmentController.cs index d76f485df7..78634f0bfc 100644 --- a/Jellyfin.Api/Controllers/HlsSegmentController.cs +++ b/Jellyfin.Api/Controllers/HlsSegmentController.cs @@ -69,7 +69,7 @@ namespace Jellyfin.Api.Controllers return BadRequest("Invalid segment."); } - return FileStreamResponseHelpers.GetStaticFileResult(file, MimeTypes.GetMimeType(file), HttpContext); + return FileStreamResponseHelpers.GetStaticFileResult(file, MimeTypes.GetMimeType(file)); } /// @@ -186,7 +186,7 @@ namespace Jellyfin.Api.Controllers return Task.CompletedTask; }); - return FileStreamResponseHelpers.GetStaticFileResult(path, MimeTypes.GetMimeType(path), HttpContext); + return FileStreamResponseHelpers.GetStaticFileResult(path, MimeTypes.GetMimeType(path)); } } } diff --git a/Jellyfin.Api/Controllers/VideosController.cs b/Jellyfin.Api/Controllers/VideosController.cs index 47eacd36b9..3ea1f75257 100644 --- a/Jellyfin.Api/Controllers/VideosController.cs +++ b/Jellyfin.Api/Controllers/VideosController.cs @@ -499,8 +499,7 @@ namespace Jellyfin.Api.Controllers return FileStreamResponseHelpers.GetStaticFileResult( state.MediaPath, - contentType, - HttpContext); + contentType); } // Need to start ffmpeg (because media can't be returned directly) diff --git a/Jellyfin.Api/Helpers/AudioHelper.cs b/Jellyfin.Api/Helpers/AudioHelper.cs index b831e81306..27497cd599 100644 --- a/Jellyfin.Api/Helpers/AudioHelper.cs +++ b/Jellyfin.Api/Helpers/AudioHelper.cs @@ -167,8 +167,7 @@ namespace Jellyfin.Api.Helpers return FileStreamResponseHelpers.GetStaticFileResult( state.MediaPath, - contentType, - _httpContextAccessor.HttpContext); + contentType); } // Need to start ffmpeg (because media can't be returned directly) diff --git a/Jellyfin.Api/Helpers/FileStreamResponseHelpers.cs b/Jellyfin.Api/Helpers/FileStreamResponseHelpers.cs index c99b911bbd..5bdd3fe2e8 100644 --- a/Jellyfin.Api/Helpers/FileStreamResponseHelpers.cs +++ b/Jellyfin.Api/Helpers/FileStreamResponseHelpers.cs @@ -51,12 +51,10 @@ namespace Jellyfin.Api.Helpers /// /// The path to the file. /// The content type of the file. - /// The current http context. /// An the file. public static ActionResult GetStaticFileResult( string path, - string contentType, - HttpContext httpContext) + string contentType) { return new PhysicalFileResult(path, contentType) { EnableRangeProcessing = true }; }