Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add default redirect type to regex handler #159

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
// Copyright (c) Geta Digital. All rights reserved.
// Copyright (c) Geta Digital. All rights reserved.
// Licensed under Apache-2.0. See the LICENSE file in the project root for more information

using System.Text.RegularExpressions;
using Geta.NotFoundHandler.Core.Redirects;
using Geta.NotFoundHandler.Data;
using Geta.NotFoundHandler.Infrastructure.Configuration;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;

namespace Geta.NotFoundHandler.Core.Providers.RegexRedirects;

public class RegexRedirectNotFoundHandler : INotFoundHandler
{
private readonly IRegexRedirectLoader _regexRedirectLoader;
private readonly ILogger<RegexRedirectNotFoundHandler> _logger;
private readonly NotFoundHandlerOptions _options;

public RegexRedirectNotFoundHandler(IRegexRedirectLoader regexRedirectLoader, ILogger<RegexRedirectNotFoundHandler> logger)
public RegexRedirectNotFoundHandler(
IRegexRedirectLoader regexRedirectLoader,
ILogger<RegexRedirectNotFoundHandler> logger,
IOptions<NotFoundHandlerOptions> options)
{
_regexRedirectLoader = regexRedirectLoader;
_logger = logger;
_options = options.Value;
}

public RewriteResult RewriteUrl(string url)
Expand All @@ -31,7 +38,7 @@ public RewriteResult RewriteUrl(string url)
if (match.Success)
{
var newUrl = match.Result(redirect.NewUrlFormat);
return new RewriteResult(newUrl, RedirectType.Temporary);
return new RewriteResult(newUrl, _options.DefaultRedirectType);
}
}
catch (RegexMatchTimeoutException e)
Expand Down