You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.1 KiB
46 lines
1.1 KiB
using Nancy;
|
|
using Nancy.Bootstrapper;
|
|
using Nancy.Responses;
|
|
using NzbDrone.Common.Extensions;
|
|
using NzbDrone.Core.Configuration;
|
|
|
|
namespace Lidarr.Http.Extensions.Pipelines
|
|
{
|
|
public class UrlBasePipeline : IRegisterNancyPipeline
|
|
{
|
|
private readonly string _urlBase;
|
|
|
|
public UrlBasePipeline(IConfigFileProvider configFileProvider)
|
|
{
|
|
_urlBase = configFileProvider.UrlBase;
|
|
}
|
|
|
|
public int Order => 99;
|
|
|
|
public void Register(IPipelines pipelines)
|
|
{
|
|
if (_urlBase.IsNotNullOrWhiteSpace())
|
|
{
|
|
pipelines.BeforeRequest.AddItemToStartOfPipeline(Handle);
|
|
}
|
|
}
|
|
|
|
private Response Handle(NancyContext context)
|
|
{
|
|
var basePath = context.Request.Url.BasePath;
|
|
|
|
if (basePath.IsNullOrWhiteSpace())
|
|
{
|
|
return new RedirectResponse($"{_urlBase}{context.Request.Path}{context.Request.Url.Query}");
|
|
}
|
|
|
|
if (_urlBase != basePath)
|
|
{
|
|
return new NotFoundResponse();
|
|
}
|
|
|
|
return null;
|
|
}
|
|
}
|
|
}
|