Skip to content

The Free Software Media System - Server Backend & API

Append base URL if the published server URL override omits it. Fleshed out unit tests to cover that and https->http reverse proxy scenario(s).

WizardOfYendor197e666c56639
diff --git a/Jellyfin.Api/Helpers/MediaInfoHelper.cs b/Jellyfin.Api/Helpers/MediaInfoHelper.cs
index 31e907549c..c27a18831c 100644
--- a/Jellyfin.Api/Helpers/MediaInfoHelper.cs
+++ b/Jellyfin.Api/Helpers/MediaInfoHelper.cs
@@ -555,11 +555,6 @@ public class MediaInfoHelper
return;
}
- if (mediaSource.Protocol != MediaProtocol.Http)
- {
- return;
- }
-
var baseUrl = _serverConfigurationManager.GetNetworkConfiguration().BaseUrl;
var publishedPath = GetPublishedLiveStreamPath(_appHost.GetSmartApiUrl(request), mediaSource.Path, mediaSource.Protocol, baseUrl);
@@ -613,6 +608,20 @@ public class MediaInfoHelper
return null;
}
- return smartApiUrl.TrimEnd('/') + relativePath;
+ var prefix = smartApiUrl.TrimEnd('/');
+ if (!string.IsNullOrEmpty(baseUrl))
+ {
+ var includesBaseUrl = Uri.TryCreate(prefix, UriKind.Absolute, out var publishedUri)
+ && Uri.UnescapeDataString(publishedUri.AbsolutePath)
+ .TrimEnd('/')
+ .EndsWith(baseUrl, StringComparison.OrdinalIgnoreCase);
+
+ if (!includesBaseUrl)
+ {
+ prefix += baseUrl;
+ }
+ }
+
+ return prefix + relativePath;
}
}
diff --git a/tests/Jellyfin.Api.Tests/Helpers/MediaInfoHelperTests.cs b/tests/Jellyfin.Api.Tests/Helpers/MediaInfoHelperTests.cs
index d93935a9d0..fe824eddd9 100644
--- a/tests/Jellyfin.Api.Tests/Helpers/MediaInfoHelperTests.cs
+++ b/tests/Jellyfin.Api.Tests/Helpers/MediaInfoHelperTests.cs
@@ -433,6 +433,48 @@ namespace Jellyfin.Api.Tests.Helpers
MediaProtocol.Http,
"",
"https://media.example.com" + LiveStreamFilesPath)]
+ [InlineData(
+ "https://media.example.com",
+ "https://172.19.0.3:8920" + LiveStreamFilesPath,
+ MediaProtocol.Http,
+ "",
+ "https://media.example.com" + LiveStreamFilesPath)]
+ [InlineData(
+ "https://media.example.com",
+ "http://192.168.1.10:8096" + LiveStreamFilesPath,
+ MediaProtocol.Http,
+ "",
+ "https://media.example.com" + LiveStreamFilesPath)]
+ [InlineData(
+ "https://media.example.com:8920",
+ "http://172.19.0.3:8096" + LiveStreamFilesPath,
+ MediaProtocol.Http,
+ "",
+ "https://media.example.com:8920" + LiveStreamFilesPath)]
+ [InlineData(
+ "https://media.example.com",
+ "http://172.19.0.3:8096/jellyfin" + LiveStreamFilesPath,
+ MediaProtocol.Http,
+ "/jellyfin",
+ "https://media.example.com/jellyfin" + LiveStreamFilesPath)]
+ [InlineData(
+ "https://jellyfin",
+ "http://172.19.0.3:8096/jellyfin" + LiveStreamFilesPath,
+ MediaProtocol.Http,
+ "/jellyfin",
+ "https://jellyfin/jellyfin" + LiveStreamFilesPath)]
+ [InlineData(
+ "https://media.example.com/jellyfin",
+ "http://172.19.0.3:8096/jellyfin" + LiveStreamFilesPath,
+ MediaProtocol.Http,
+ "/jellyfin",
+ "https://media.example.com/jellyfin" + LiveStreamFilesPath)]
+ [InlineData(
+ "https://media.example.com/jellyfin/",
+ "http://172.19.0.3:8096/jellyfin" + LiveStreamFilesPath,
+ MediaProtocol.Http,
+ "/jellyfin",
+ "https://media.example.com/jellyfin" + LiveStreamFilesPath)]
[InlineData(
"https://media.example.com",
"http://172.19.0.3:8096/jellyfin2" + LiveStreamFilesPath,