mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-07-09 03:04:24 -04:00
Merge pull request #1863 from joshuaboniface/fix-baseurl-issues
Fix inconsistent BaseUrl behavior
This commit is contained in:
commit
1176749f14
@ -39,6 +39,7 @@ namespace Emby.Server.Implementations.HttpServer
|
|||||||
private readonly IHttpListener _socketListener;
|
private readonly IHttpListener _socketListener;
|
||||||
private readonly Func<Type, Func<string, object>> _funcParseFn;
|
private readonly Func<Type, Func<string, object>> _funcParseFn;
|
||||||
private readonly string _defaultRedirectPath;
|
private readonly string _defaultRedirectPath;
|
||||||
|
private readonly string _baseUrlPrefix;
|
||||||
private readonly Dictionary<Type, Type> ServiceOperationsMap = new Dictionary<Type, Type>();
|
private readonly Dictionary<Type, Type> ServiceOperationsMap = new Dictionary<Type, Type>();
|
||||||
private IWebSocketListener[] _webSocketListeners = Array.Empty<IWebSocketListener>();
|
private IWebSocketListener[] _webSocketListeners = Array.Empty<IWebSocketListener>();
|
||||||
private readonly List<IWebSocketConnection> _webSocketConnections = new List<IWebSocketConnection>();
|
private readonly List<IWebSocketConnection> _webSocketConnections = new List<IWebSocketConnection>();
|
||||||
@ -58,6 +59,7 @@ namespace Emby.Server.Implementations.HttpServer
|
|||||||
_logger = logger;
|
_logger = logger;
|
||||||
_config = config;
|
_config = config;
|
||||||
_defaultRedirectPath = configuration["HttpListenerHost:DefaultRedirectPath"];
|
_defaultRedirectPath = configuration["HttpListenerHost:DefaultRedirectPath"];
|
||||||
|
_baseUrlPrefix = _config.Configuration.BaseUrl;
|
||||||
_networkManager = networkManager;
|
_networkManager = networkManager;
|
||||||
_jsonSerializer = jsonSerializer;
|
_jsonSerializer = jsonSerializer;
|
||||||
_xmlSerializer = xmlSerializer;
|
_xmlSerializer = xmlSerializer;
|
||||||
@ -87,6 +89,20 @@ namespace Emby.Server.Implementations.HttpServer
|
|||||||
return _appHost.CreateInstance(type);
|
return _appHost.CreateInstance(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static string NormalizeUrlPath(string path)
|
||||||
|
{
|
||||||
|
if (path.StartsWith("/"))
|
||||||
|
{
|
||||||
|
// If the path begins with a leading slash, just return it as-is
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// If the path does not begin with a leading slash, append one for consistency
|
||||||
|
return "/" + path;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Applies the request filters. Returns whether or not the request has been handled
|
/// Applies the request filters. Returns whether or not the request has been handled
|
||||||
/// and no more processing should be done.
|
/// and no more processing should be done.
|
||||||
@ -473,22 +489,15 @@ namespace Emby.Server.Implementations.HttpServer
|
|||||||
|
|
||||||
urlToLog = GetUrlToLog(urlString);
|
urlToLog = GetUrlToLog(urlString);
|
||||||
|
|
||||||
if (string.Equals(localPath, "/" + _config.Configuration.BaseUrl + "/", StringComparison.OrdinalIgnoreCase)
|
if (string.Equals(localPath, _baseUrlPrefix + "/", StringComparison.OrdinalIgnoreCase)
|
||||||
|| string.Equals(localPath, "/" + _config.Configuration.BaseUrl, StringComparison.OrdinalIgnoreCase))
|
|| string.Equals(localPath, _baseUrlPrefix, StringComparison.OrdinalIgnoreCase)
|
||||||
|
|| string.Equals(localPath, "/", StringComparison.OrdinalIgnoreCase)
|
||||||
|
|| string.IsNullOrEmpty(localPath)
|
||||||
|
|| !localPath.StartsWith(_baseUrlPrefix))
|
||||||
{
|
{
|
||||||
httpRes.Redirect("/" + _config.Configuration.BaseUrl + "/" + _defaultRedirectPath);
|
// Always redirect back to the default path if the base prefix is invalid or missing
|
||||||
return;
|
_logger.LogDebug("Normalizing a URL at {0}", localPath);
|
||||||
}
|
httpRes.Redirect(_baseUrlPrefix + "/" + _defaultRedirectPath);
|
||||||
|
|
||||||
if (string.Equals(localPath, "/", StringComparison.OrdinalIgnoreCase))
|
|
||||||
{
|
|
||||||
httpRes.Redirect(_defaultRedirectPath);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(localPath))
|
|
||||||
{
|
|
||||||
httpRes.Redirect("/" + _defaultRedirectPath);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -598,7 +607,7 @@ namespace Emby.Server.Implementations.HttpServer
|
|||||||
|
|
||||||
foreach (var route in clone)
|
foreach (var route in clone)
|
||||||
{
|
{
|
||||||
routes.Add(new RouteAttribute(NormalizeCustomRoutePath(_config.Configuration.BaseUrl, route.Path), route.Verbs)
|
routes.Add(new RouteAttribute(NormalizeCustomRoutePath(route.Path), route.Verbs)
|
||||||
{
|
{
|
||||||
Notes = route.Notes,
|
Notes = route.Notes,
|
||||||
Priority = route.Priority,
|
Priority = route.Priority,
|
||||||
@ -653,36 +662,22 @@ namespace Emby.Server.Implementations.HttpServer
|
|||||||
return _socketListener.ProcessWebSocketRequest(context);
|
return _socketListener.ProcessWebSocketRequest(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
// this method was left for compatibility with third party clients
|
private string NormalizeEmbyRoutePath(string path)
|
||||||
private static string NormalizeEmbyRoutePath(string path)
|
|
||||||
{
|
{
|
||||||
if (path.StartsWith("/", StringComparison.OrdinalIgnoreCase))
|
_logger.LogDebug("Normalizing /emby route");
|
||||||
{
|
return _baseUrlPrefix + "/emby" + NormalizeUrlPath(path);
|
||||||
return "/emby" + path;
|
|
||||||
}
|
|
||||||
|
|
||||||
return "emby/" + path;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// this method was left for compatibility with third party clients
|
private string NormalizeMediaBrowserRoutePath(string path)
|
||||||
private static string NormalizeMediaBrowserRoutePath(string path)
|
|
||||||
{
|
{
|
||||||
if (path.StartsWith("/", StringComparison.OrdinalIgnoreCase))
|
_logger.LogDebug("Normalizing /mediabrowser route");
|
||||||
{
|
return _baseUrlPrefix + "/mediabrowser" + NormalizeUrlPath(path);
|
||||||
return "/mediabrowser" + path;
|
|
||||||
}
|
|
||||||
|
|
||||||
return "mediabrowser/" + path;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string NormalizeCustomRoutePath(string baseUrl, string path)
|
private string NormalizeCustomRoutePath(string path)
|
||||||
{
|
{
|
||||||
if (path.StartsWith("/", StringComparison.OrdinalIgnoreCase))
|
_logger.LogDebug("Normalizing custom route {0}", path);
|
||||||
{
|
return _baseUrlPrefix + NormalizeUrlPath(path);
|
||||||
return "/" + baseUrl + path;
|
|
||||||
}
|
|
||||||
|
|
||||||
return baseUrl + "/" + path;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
@ -10,6 +10,7 @@ namespace MediaBrowser.Model.Configuration
|
|||||||
{
|
{
|
||||||
public const int DefaultHttpPort = 8096;
|
public const int DefaultHttpPort = 8096;
|
||||||
public const int DefaultHttpsPort = 8920;
|
public const int DefaultHttpsPort = 8920;
|
||||||
|
private string _baseUrl;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets a value indicating whether [enable u pn p].
|
/// Gets or sets a value indicating whether [enable u pn p].
|
||||||
@ -162,7 +163,33 @@ namespace MediaBrowser.Model.Configuration
|
|||||||
public bool SkipDeserializationForBasicTypes { get; set; }
|
public bool SkipDeserializationForBasicTypes { get; set; }
|
||||||
|
|
||||||
public string ServerName { get; set; }
|
public string ServerName { get; set; }
|
||||||
public string BaseUrl { get; set; }
|
public string BaseUrl
|
||||||
|
{
|
||||||
|
get => _baseUrl;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
// Normalize the start of the string
|
||||||
|
if (string.IsNullOrWhiteSpace(value))
|
||||||
|
{
|
||||||
|
// If baseUrl is empty, set an empty prefix string
|
||||||
|
value = string.Empty;
|
||||||
|
}
|
||||||
|
else if (!value.StartsWith("/"))
|
||||||
|
{
|
||||||
|
// If baseUrl was not configured with a leading slash, append one for consistency
|
||||||
|
value = "/" + value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Normalize the end of the string
|
||||||
|
if (value.EndsWith("/"))
|
||||||
|
{
|
||||||
|
// If baseUrl was configured with a trailing slash, remove it for consistency
|
||||||
|
value = value.Remove(value.Length - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
_baseUrl = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public string UICulture { get; set; }
|
public string UICulture { get; set; }
|
||||||
|
|
||||||
@ -243,7 +270,7 @@ namespace MediaBrowser.Model.Configuration
|
|||||||
SortRemoveCharacters = new[] { ",", "&", "-", "{", "}", "'" };
|
SortRemoveCharacters = new[] { ",", "&", "-", "{", "}", "'" };
|
||||||
SortRemoveWords = new[] { "the", "a", "an" };
|
SortRemoveWords = new[] { "the", "a", "an" };
|
||||||
|
|
||||||
BaseUrl = "jellyfin";
|
BaseUrl = string.Empty;
|
||||||
UICulture = "en-US";
|
UICulture = "en-US";
|
||||||
|
|
||||||
MetadataOptions = new[]
|
MetadataOptions = new[]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user