2019-01-22 07:30:04 +00:00
|
|
|
package redirect
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"net/http"
|
|
|
|
|
2019-08-03 01:58:23 +00:00
|
|
|
"github.com/containous/traefik/v2/pkg/config/dynamic"
|
2019-09-13 17:28:04 +00:00
|
|
|
"github.com/containous/traefik/v2/pkg/log"
|
2019-08-03 01:58:23 +00:00
|
|
|
"github.com/containous/traefik/v2/pkg/middlewares"
|
2019-01-22 07:30:04 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
typeRegexName = "RedirectRegex"
|
|
|
|
)
|
|
|
|
|
|
|
|
// NewRedirectRegex creates a redirect middleware.
|
2019-07-10 07:26:04 +00:00
|
|
|
func NewRedirectRegex(ctx context.Context, next http.Handler, conf dynamic.RedirectRegex, name string) (http.Handler, error) {
|
2019-09-13 17:28:04 +00:00
|
|
|
logger := log.FromContext(middlewares.GetLoggerCtx(ctx, name, typeRegexName))
|
2019-01-22 07:30:04 +00:00
|
|
|
logger.Debug("Creating middleware")
|
|
|
|
logger.Debugf("Setting up redirection from %s to %s", conf.Regex, conf.Replacement)
|
|
|
|
|
2019-09-13 17:28:04 +00:00
|
|
|
return newRedirect(next, conf.Regex, conf.Replacement, conf.Permanent, name)
|
2019-01-22 07:30:04 +00:00
|
|
|
}
|