Merge pull request #5803 from crobibero/healthy-base-url
This commit is contained in:
commit
9963d0ce5e
|
@ -45,16 +45,26 @@ namespace Jellyfin.Server.Middleware
|
||||||
var localPath = httpContext.Request.Path.ToString();
|
var localPath = httpContext.Request.Path.ToString();
|
||||||
var baseUrlPrefix = serverConfigurationManager.GetNetworkConfiguration().BaseUrl;
|
var baseUrlPrefix = serverConfigurationManager.GetNetworkConfiguration().BaseUrl;
|
||||||
|
|
||||||
if (string.Equals(localPath, baseUrlPrefix + "/", StringComparison.OrdinalIgnoreCase)
|
if (!string.IsNullOrEmpty(baseUrlPrefix))
|
||||||
|| string.Equals(localPath, baseUrlPrefix, StringComparison.OrdinalIgnoreCase)
|
|
||||||
|| string.Equals(localPath, "/", StringComparison.OrdinalIgnoreCase)
|
|
||||||
|| string.IsNullOrEmpty(localPath)
|
|
||||||
|| !localPath.StartsWith(baseUrlPrefix, StringComparison.OrdinalIgnoreCase))
|
|
||||||
{
|
{
|
||||||
// Always redirect back to the default path if the base prefix is invalid or missing
|
var startsWithBaseUrl = localPath.StartsWith(baseUrlPrefix, StringComparison.OrdinalIgnoreCase);
|
||||||
_logger.LogDebug("Normalizing an URL at {LocalPath}", localPath);
|
|
||||||
httpContext.Response.Redirect(baseUrlPrefix + "/" + _configuration[ConfigurationExtensions.DefaultRedirectKey]);
|
if (!startsWithBaseUrl
|
||||||
return;
|
&& (localPath.Equals("/health", StringComparison.OrdinalIgnoreCase)
|
||||||
|
|| localPath.Equals("/health/", StringComparison.OrdinalIgnoreCase)))
|
||||||
|
{
|
||||||
|
_logger.LogDebug("Redirecting /health check");
|
||||||
|
httpContext.Response.Redirect(baseUrlPrefix + "/health");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!startsWithBaseUrl)
|
||||||
|
{
|
||||||
|
// Always redirect back to the default path if the base prefix is invalid or missing
|
||||||
|
_logger.LogDebug("Normalizing an URL at {LocalPath}", localPath);
|
||||||
|
httpContext.Response.Redirect(baseUrlPrefix + "/" + _configuration[ConfigurationExtensions.DefaultRedirectKey]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await _next(httpContext).ConfigureAwait(false);
|
await _next(httpContext).ConfigureAwait(false);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user