Move dynamic config into a dedicated package.
This commit is contained in:
parent
09cc1161c9
commit
c8bf8e896a
102 changed files with 3170 additions and 3166 deletions
|
@ -5,7 +5,7 @@ import (
|
|||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/containous/traefik/pkg/config"
|
||||
"github.com/containous/traefik/pkg/config/dynamic"
|
||||
"github.com/containous/traefik/pkg/middlewares"
|
||||
"github.com/containous/traefik/pkg/tracing"
|
||||
"github.com/opentracing/opentracing-go/ext"
|
||||
|
@ -23,7 +23,7 @@ type addPrefix struct {
|
|||
}
|
||||
|
||||
// New creates a new handler.
|
||||
func New(ctx context.Context, next http.Handler, config config.AddPrefix, name string) (http.Handler, error) {
|
||||
func New(ctx context.Context, next http.Handler, config dynamic.AddPrefix, name string) (http.Handler, error) {
|
||||
middlewares.GetLogger(ctx, name, typeName).Debug("Creating middleware")
|
||||
var result *addPrefix
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
"net/http"
|
||||
"testing"
|
||||
|
||||
"github.com/containous/traefik/pkg/config"
|
||||
"github.com/containous/traefik/pkg/config/dynamic"
|
||||
"github.com/containous/traefik/pkg/testhelpers"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
@ -15,16 +15,16 @@ import (
|
|||
func TestNewAddPrefix(t *testing.T) {
|
||||
testCases := []struct {
|
||||
desc string
|
||||
prefix config.AddPrefix
|
||||
prefix dynamic.AddPrefix
|
||||
expectsError bool
|
||||
}{
|
||||
{
|
||||
desc: "Works with a non empty prefix",
|
||||
prefix: config.AddPrefix{Prefix: "/a"},
|
||||
prefix: dynamic.AddPrefix{Prefix: "/a"},
|
||||
},
|
||||
{
|
||||
desc: "Fails if prefix is empty",
|
||||
prefix: config.AddPrefix{Prefix: ""},
|
||||
prefix: dynamic.AddPrefix{Prefix: ""},
|
||||
expectsError: true,
|
||||
},
|
||||
}
|
||||
|
@ -50,20 +50,20 @@ func TestAddPrefix(t *testing.T) {
|
|||
logrus.SetLevel(logrus.DebugLevel)
|
||||
testCases := []struct {
|
||||
desc string
|
||||
prefix config.AddPrefix
|
||||
prefix dynamic.AddPrefix
|
||||
path string
|
||||
expectedPath string
|
||||
expectedRawPath string
|
||||
}{
|
||||
{
|
||||
desc: "Works with a regular path",
|
||||
prefix: config.AddPrefix{Prefix: "/a"},
|
||||
prefix: dynamic.AddPrefix{Prefix: "/a"},
|
||||
path: "/b",
|
||||
expectedPath: "/a/b",
|
||||
},
|
||||
{
|
||||
desc: "Works with a raw path",
|
||||
prefix: config.AddPrefix{Prefix: "/a"},
|
||||
prefix: dynamic.AddPrefix{Prefix: "/a"},
|
||||
path: "/b%2Fc",
|
||||
expectedPath: "/a/b/c",
|
||||
expectedRawPath: "/a/b%2Fc",
|
||||
|
|
|
@ -8,7 +8,7 @@ import (
|
|||
"strings"
|
||||
|
||||
goauth "github.com/abbot/go-http-auth"
|
||||
"github.com/containous/traefik/pkg/config"
|
||||
"github.com/containous/traefik/pkg/config/dynamic"
|
||||
"github.com/containous/traefik/pkg/middlewares"
|
||||
"github.com/containous/traefik/pkg/middlewares/accesslog"
|
||||
"github.com/containous/traefik/pkg/tracing"
|
||||
|
@ -29,7 +29,7 @@ type basicAuth struct {
|
|||
}
|
||||
|
||||
// NewBasic creates a basicAuth middleware.
|
||||
func NewBasic(ctx context.Context, next http.Handler, authConfig config.BasicAuth, name string) (http.Handler, error) {
|
||||
func NewBasic(ctx context.Context, next http.Handler, authConfig dynamic.BasicAuth, name string) (http.Handler, error) {
|
||||
middlewares.GetLogger(ctx, name, basicTypeName).Debug("Creating middleware")
|
||||
users, err := getUsers(authConfig.UsersFile, authConfig.Users, basicUserParser)
|
||||
if err != nil {
|
||||
|
|
|
@ -9,7 +9,7 @@ import (
|
|||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/containous/traefik/pkg/config"
|
||||
"github.com/containous/traefik/pkg/config/dynamic"
|
||||
"github.com/containous/traefik/pkg/testhelpers"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
@ -20,13 +20,13 @@ func TestBasicAuthFail(t *testing.T) {
|
|||
fmt.Fprintln(w, "traefik")
|
||||
})
|
||||
|
||||
auth := config.BasicAuth{
|
||||
auth := dynamic.BasicAuth{
|
||||
Users: []string{"test"},
|
||||
}
|
||||
_, err := NewBasic(context.Background(), next, auth, "authName")
|
||||
require.Error(t, err)
|
||||
|
||||
auth2 := config.BasicAuth{
|
||||
auth2 := dynamic.BasicAuth{
|
||||
Users: []string{"test:test"},
|
||||
}
|
||||
authMiddleware, err := NewBasic(context.Background(), next, auth2, "authTest")
|
||||
|
@ -49,7 +49,7 @@ func TestBasicAuthSuccess(t *testing.T) {
|
|||
fmt.Fprintln(w, "traefik")
|
||||
})
|
||||
|
||||
auth := config.BasicAuth{
|
||||
auth := dynamic.BasicAuth{
|
||||
Users: []string{"test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/"},
|
||||
}
|
||||
authMiddleware, err := NewBasic(context.Background(), next, auth, "authName")
|
||||
|
@ -79,7 +79,7 @@ func TestBasicAuthUserHeader(t *testing.T) {
|
|||
fmt.Fprintln(w, "traefik")
|
||||
})
|
||||
|
||||
auth := config.BasicAuth{
|
||||
auth := dynamic.BasicAuth{
|
||||
Users: []string{"test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/"},
|
||||
HeaderField: "X-Webauth-User",
|
||||
}
|
||||
|
@ -110,7 +110,7 @@ func TestBasicAuthHeaderRemoved(t *testing.T) {
|
|||
fmt.Fprintln(w, "traefik")
|
||||
})
|
||||
|
||||
auth := config.BasicAuth{
|
||||
auth := dynamic.BasicAuth{
|
||||
RemoveHeader: true,
|
||||
Users: []string{"test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/"},
|
||||
}
|
||||
|
@ -142,7 +142,7 @@ func TestBasicAuthHeaderPresent(t *testing.T) {
|
|||
fmt.Fprintln(w, "traefik")
|
||||
})
|
||||
|
||||
auth := config.BasicAuth{
|
||||
auth := dynamic.BasicAuth{
|
||||
Users: []string{"test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/"},
|
||||
}
|
||||
middleware, err := NewBasic(context.Background(), next, auth, "authName")
|
||||
|
@ -226,7 +226,7 @@ func TestBasicAuthUsersFromFile(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
|
||||
// Creates the configuration for our Authenticator
|
||||
authenticatorConfiguration := config.BasicAuth{
|
||||
authenticatorConfiguration := dynamic.BasicAuth{
|
||||
Users: test.givenUsers,
|
||||
UsersFile: usersFile.Name(),
|
||||
Realm: test.realm,
|
||||
|
|
|
@ -8,7 +8,7 @@ import (
|
|||
"strings"
|
||||
|
||||
goauth "github.com/abbot/go-http-auth"
|
||||
"github.com/containous/traefik/pkg/config"
|
||||
"github.com/containous/traefik/pkg/config/dynamic"
|
||||
"github.com/containous/traefik/pkg/middlewares"
|
||||
"github.com/containous/traefik/pkg/middlewares/accesslog"
|
||||
"github.com/containous/traefik/pkg/tracing"
|
||||
|
@ -29,7 +29,7 @@ type digestAuth struct {
|
|||
}
|
||||
|
||||
// NewDigest creates a digest auth middleware.
|
||||
func NewDigest(ctx context.Context, next http.Handler, authConfig config.DigestAuth, name string) (http.Handler, error) {
|
||||
func NewDigest(ctx context.Context, next http.Handler, authConfig dynamic.DigestAuth, name string) (http.Handler, error) {
|
||||
middlewares.GetLogger(ctx, name, digestTypeName).Debug("Creating middleware")
|
||||
users, err := getUsers(authConfig.UsersFile, authConfig.Users, digestUserParser)
|
||||
if err != nil {
|
||||
|
|
|
@ -9,7 +9,7 @@ import (
|
|||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/containous/traefik/pkg/config"
|
||||
"github.com/containous/traefik/pkg/config/dynamic"
|
||||
"github.com/containous/traefik/pkg/testhelpers"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
@ -20,7 +20,7 @@ func TestDigestAuthError(t *testing.T) {
|
|||
fmt.Fprintln(w, "traefik")
|
||||
})
|
||||
|
||||
auth := config.DigestAuth{
|
||||
auth := dynamic.DigestAuth{
|
||||
Users: []string{"test"},
|
||||
}
|
||||
_, err := NewDigest(context.Background(), next, auth, "authName")
|
||||
|
@ -32,7 +32,7 @@ func TestDigestAuthFail(t *testing.T) {
|
|||
fmt.Fprintln(w, "traefik")
|
||||
})
|
||||
|
||||
auth := config.DigestAuth{
|
||||
auth := dynamic.DigestAuth{
|
||||
Users: []string{"test:traefik:a2688e031edb4be6a3797f3882655c05"},
|
||||
}
|
||||
authMiddleware, err := NewDigest(context.Background(), next, auth, "authName")
|
||||
|
@ -101,7 +101,7 @@ func TestDigestAuthUsersFromFile(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
|
||||
// Creates the configuration for our Authenticator
|
||||
authenticatorConfiguration := config.DigestAuth{
|
||||
authenticatorConfiguration := dynamic.DigestAuth{
|
||||
Users: test.givenUsers,
|
||||
UsersFile: usersFile.Name(),
|
||||
Realm: test.realm,
|
||||
|
|
|
@ -9,7 +9,7 @@ import (
|
|||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/containous/traefik/pkg/config"
|
||||
"github.com/containous/traefik/pkg/config/dynamic"
|
||||
"github.com/containous/traefik/pkg/middlewares"
|
||||
"github.com/containous/traefik/pkg/tracing"
|
||||
"github.com/opentracing/opentracing-go/ext"
|
||||
|
@ -33,7 +33,7 @@ type forwardAuth struct {
|
|||
}
|
||||
|
||||
// NewForward creates a forward auth middleware.
|
||||
func NewForward(ctx context.Context, next http.Handler, config config.ForwardAuth, name string) (http.Handler, error) {
|
||||
func NewForward(ctx context.Context, next http.Handler, config dynamic.ForwardAuth, name string) (http.Handler, error) {
|
||||
middlewares.GetLogger(ctx, name, forwardedTypeName).Debug("Creating middleware")
|
||||
|
||||
fa := &forwardAuth{
|
||||
|
|
|
@ -8,7 +8,7 @@ import (
|
|||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"github.com/containous/traefik/pkg/config"
|
||||
"github.com/containous/traefik/pkg/config/dynamic"
|
||||
"github.com/containous/traefik/pkg/testhelpers"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
@ -25,7 +25,7 @@ func TestForwardAuthFail(t *testing.T) {
|
|||
}))
|
||||
defer server.Close()
|
||||
|
||||
middleware, err := NewForward(context.Background(), next, config.ForwardAuth{
|
||||
middleware, err := NewForward(context.Background(), next, dynamic.ForwardAuth{
|
||||
Address: server.URL,
|
||||
}, "authTest")
|
||||
require.NoError(t, err)
|
||||
|
@ -63,7 +63,7 @@ func TestForwardAuthSuccess(t *testing.T) {
|
|||
fmt.Fprintln(w, "traefik")
|
||||
})
|
||||
|
||||
auth := config.ForwardAuth{
|
||||
auth := dynamic.ForwardAuth{
|
||||
Address: server.URL,
|
||||
AuthResponseHeaders: []string{"X-Auth-User", "X-Auth-Group"},
|
||||
}
|
||||
|
@ -96,7 +96,7 @@ func TestForwardAuthRedirect(t *testing.T) {
|
|||
fmt.Fprintln(w, "traefik")
|
||||
})
|
||||
|
||||
auth := config.ForwardAuth{
|
||||
auth := dynamic.ForwardAuth{
|
||||
Address: authTs.URL,
|
||||
}
|
||||
authMiddleware, err := NewForward(context.Background(), next, auth, "authTest")
|
||||
|
@ -147,7 +147,7 @@ func TestForwardAuthRemoveHopByHopHeaders(t *testing.T) {
|
|||
next := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprintln(w, "traefik")
|
||||
})
|
||||
auth := config.ForwardAuth{
|
||||
auth := dynamic.ForwardAuth{
|
||||
Address: authTs.URL,
|
||||
}
|
||||
authMiddleware, err := NewForward(context.Background(), next, auth, "authTest")
|
||||
|
@ -193,7 +193,7 @@ func TestForwardAuthFailResponseHeaders(t *testing.T) {
|
|||
fmt.Fprintln(w, "traefik")
|
||||
})
|
||||
|
||||
auth := config.ForwardAuth{
|
||||
auth := dynamic.ForwardAuth{
|
||||
Address: authTs.URL,
|
||||
}
|
||||
authMiddleware, err := NewForward(context.Background(), next, auth, "authTest")
|
||||
|
|
|
@ -4,7 +4,7 @@ import (
|
|||
"context"
|
||||
"net/http"
|
||||
|
||||
"github.com/containous/traefik/pkg/config"
|
||||
"github.com/containous/traefik/pkg/config/dynamic"
|
||||
"github.com/containous/traefik/pkg/middlewares"
|
||||
"github.com/containous/traefik/pkg/tracing"
|
||||
"github.com/opentracing/opentracing-go/ext"
|
||||
|
@ -21,7 +21,7 @@ type buffer struct {
|
|||
}
|
||||
|
||||
// New creates a buffering middleware.
|
||||
func New(ctx context.Context, next http.Handler, config config.Buffering, name string) (http.Handler, error) {
|
||||
func New(ctx context.Context, next http.Handler, config dynamic.Buffering, name string) (http.Handler, error) {
|
||||
logger := middlewares.GetLogger(ctx, name, typeName)
|
||||
logger.Debug("Creating middleware")
|
||||
logger.Debug("Setting up buffering: request limits: %d (mem), %d (max), response limits: %d (mem), %d (max) with retry: '%s'",
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
"net/http"
|
||||
|
||||
"github.com/containous/alice"
|
||||
"github.com/containous/traefik/pkg/config"
|
||||
"github.com/containous/traefik/pkg/config/dynamic"
|
||||
"github.com/containous/traefik/pkg/middlewares"
|
||||
)
|
||||
|
||||
|
@ -18,7 +18,7 @@ type chainBuilder interface {
|
|||
}
|
||||
|
||||
// New creates a chain middleware
|
||||
func New(ctx context.Context, next http.Handler, config config.Chain, builder chainBuilder, name string) (http.Handler, error) {
|
||||
func New(ctx context.Context, next http.Handler, config dynamic.Chain, builder chainBuilder, name string) (http.Handler, error) {
|
||||
middlewares.GetLogger(ctx, name, typeName).Debug("Creating middleware")
|
||||
|
||||
middlewareChain := builder.BuildChain(ctx, config.Middlewares)
|
||||
|
|
|
@ -4,7 +4,7 @@ import (
|
|||
"context"
|
||||
"net/http"
|
||||
|
||||
"github.com/containous/traefik/pkg/config"
|
||||
"github.com/containous/traefik/pkg/config/dynamic"
|
||||
"github.com/containous/traefik/pkg/log"
|
||||
"github.com/containous/traefik/pkg/middlewares"
|
||||
"github.com/containous/traefik/pkg/tracing"
|
||||
|
@ -22,7 +22,7 @@ type circuitBreaker struct {
|
|||
}
|
||||
|
||||
// New creates a new circuit breaker middleware.
|
||||
func New(ctx context.Context, next http.Handler, confCircuitBreaker config.CircuitBreaker, name string) (http.Handler, error) {
|
||||
func New(ctx context.Context, next http.Handler, confCircuitBreaker dynamic.CircuitBreaker, name string) (http.Handler, error) {
|
||||
expression := confCircuitBreaker.Expression
|
||||
|
||||
logger := middlewares.GetLogger(ctx, name, typeName)
|
||||
|
|
|
@ -11,7 +11,7 @@ import (
|
|||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/containous/traefik/pkg/config"
|
||||
"github.com/containous/traefik/pkg/config/dynamic"
|
||||
"github.com/containous/traefik/pkg/middlewares"
|
||||
"github.com/containous/traefik/pkg/tracing"
|
||||
"github.com/containous/traefik/pkg/types"
|
||||
|
@ -42,7 +42,7 @@ type customErrors struct {
|
|||
}
|
||||
|
||||
// New creates a new custom error pages middleware.
|
||||
func New(ctx context.Context, next http.Handler, config config.ErrorPage, serviceBuilder serviceBuilder, name string) (http.Handler, error) {
|
||||
func New(ctx context.Context, next http.Handler, config dynamic.ErrorPage, serviceBuilder serviceBuilder, name string) (http.Handler, error) {
|
||||
middlewares.GetLogger(ctx, name, typeName).Debug("Creating middleware")
|
||||
|
||||
httpCodeRanges, err := types.NewHTTPCodeRanges(config.Status)
|
||||
|
|
|
@ -7,7 +7,7 @@ import (
|
|||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"github.com/containous/traefik/pkg/config"
|
||||
"github.com/containous/traefik/pkg/config/dynamic"
|
||||
"github.com/containous/traefik/pkg/middlewares"
|
||||
"github.com/containous/traefik/pkg/testhelpers"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
@ -17,14 +17,14 @@ import (
|
|||
func TestHandler(t *testing.T) {
|
||||
testCases := []struct {
|
||||
desc string
|
||||
errorPage *config.ErrorPage
|
||||
errorPage *dynamic.ErrorPage
|
||||
backendCode int
|
||||
backendErrorHandler http.HandlerFunc
|
||||
validate func(t *testing.T, recorder *httptest.ResponseRecorder)
|
||||
}{
|
||||
{
|
||||
desc: "no error",
|
||||
errorPage: &config.ErrorPage{Service: "error", Query: "/test", Status: []string{"500-501", "503-599"}},
|
||||
errorPage: &dynamic.ErrorPage{Service: "error", Query: "/test", Status: []string{"500-501", "503-599"}},
|
||||
backendCode: http.StatusOK,
|
||||
backendErrorHandler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprintln(w, "My error page.")
|
||||
|
@ -36,7 +36,7 @@ func TestHandler(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "in the range",
|
||||
errorPage: &config.ErrorPage{Service: "error", Query: "/test", Status: []string{"500-501", "503-599"}},
|
||||
errorPage: &dynamic.ErrorPage{Service: "error", Query: "/test", Status: []string{"500-501", "503-599"}},
|
||||
backendCode: http.StatusInternalServerError,
|
||||
backendErrorHandler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprintln(w, "My error page.")
|
||||
|
@ -49,7 +49,7 @@ func TestHandler(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "not in the range",
|
||||
errorPage: &config.ErrorPage{Service: "error", Query: "/test", Status: []string{"500-501", "503-599"}},
|
||||
errorPage: &dynamic.ErrorPage{Service: "error", Query: "/test", Status: []string{"500-501", "503-599"}},
|
||||
backendCode: http.StatusBadGateway,
|
||||
backendErrorHandler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprintln(w, "My error page.")
|
||||
|
@ -62,7 +62,7 @@ func TestHandler(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "query replacement",
|
||||
errorPage: &config.ErrorPage{Service: "error", Query: "/{status}", Status: []string{"503-503"}},
|
||||
errorPage: &dynamic.ErrorPage{Service: "error", Query: "/{status}", Status: []string{"503-503"}},
|
||||
backendCode: http.StatusServiceUnavailable,
|
||||
backendErrorHandler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.RequestURI == "/503" {
|
||||
|
@ -79,7 +79,7 @@ func TestHandler(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "Single code",
|
||||
errorPage: &config.ErrorPage{Service: "error", Query: "/{status}", Status: []string{"503"}},
|
||||
errorPage: &dynamic.ErrorPage{Service: "error", Query: "/{status}", Status: []string{"503"}},
|
||||
backendCode: http.StatusServiceUnavailable,
|
||||
backendErrorHandler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.RequestURI == "/503" {
|
||||
|
|
|
@ -8,7 +8,7 @@ import (
|
|||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/containous/traefik/pkg/config"
|
||||
"github.com/containous/traefik/pkg/config/dynamic"
|
||||
"github.com/containous/traefik/pkg/middlewares"
|
||||
"github.com/containous/traefik/pkg/tracing"
|
||||
"github.com/opentracing/opentracing-go/ext"
|
||||
|
@ -26,7 +26,7 @@ type headers struct {
|
|||
}
|
||||
|
||||
// New creates a Headers middleware.
|
||||
func New(ctx context.Context, next http.Handler, config config.Headers, name string) (http.Handler, error) {
|
||||
func New(ctx context.Context, next http.Handler, config dynamic.Headers, name string) (http.Handler, error) {
|
||||
// HeaderMiddleware -> SecureMiddleWare -> next
|
||||
logger := middlewares.GetLogger(ctx, name, typeName)
|
||||
logger.Debug("Creating middleware")
|
||||
|
@ -73,7 +73,7 @@ type secureHeader struct {
|
|||
}
|
||||
|
||||
// newSecure constructs a new secure instance with supplied options.
|
||||
func newSecure(next http.Handler, headers config.Headers) *secureHeader {
|
||||
func newSecure(next http.Handler, headers dynamic.Headers) *secureHeader {
|
||||
opt := secure.Options{
|
||||
BrowserXssFilter: headers.BrowserXSSFilter,
|
||||
ContentTypeNosniff: headers.ContentTypeNosniff,
|
||||
|
@ -111,11 +111,11 @@ func (s secureHeader) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
|
|||
// provided to configure which features should be enabled, and the ability to override a few of the default values.
|
||||
type Header struct {
|
||||
next http.Handler
|
||||
headers *config.Headers
|
||||
headers *dynamic.Headers
|
||||
}
|
||||
|
||||
// NewHeader constructs a new header instance from supplied frontend header struct.
|
||||
func NewHeader(next http.Handler, headers config.Headers) *Header {
|
||||
func NewHeader(next http.Handler, headers dynamic.Headers) *Header {
|
||||
return &Header{
|
||||
next: next,
|
||||
headers: &headers,
|
||||
|
|
|
@ -8,7 +8,7 @@ import (
|
|||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"github.com/containous/traefik/pkg/config"
|
||||
"github.com/containous/traefik/pkg/config/dynamic"
|
||||
"github.com/containous/traefik/pkg/testhelpers"
|
||||
"github.com/containous/traefik/pkg/tracing"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
@ -18,7 +18,7 @@ import (
|
|||
func TestCustomRequestHeader(t *testing.T) {
|
||||
emptyHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})
|
||||
|
||||
header := NewHeader(emptyHandler, config.Headers{
|
||||
header := NewHeader(emptyHandler, dynamic.Headers{
|
||||
CustomRequestHeaders: map[string]string{
|
||||
"X-Custom-Request-Header": "test_request",
|
||||
},
|
||||
|
@ -36,7 +36,7 @@ func TestCustomRequestHeader(t *testing.T) {
|
|||
func TestCustomRequestHeaderEmptyValue(t *testing.T) {
|
||||
emptyHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})
|
||||
|
||||
header := NewHeader(emptyHandler, config.Headers{
|
||||
header := NewHeader(emptyHandler, dynamic.Headers{
|
||||
CustomRequestHeaders: map[string]string{
|
||||
"X-Custom-Request-Header": "test_request",
|
||||
},
|
||||
|
@ -50,7 +50,7 @@ func TestCustomRequestHeaderEmptyValue(t *testing.T) {
|
|||
assert.Equal(t, http.StatusOK, res.Code)
|
||||
assert.Equal(t, "test_request", req.Header.Get("X-Custom-Request-Header"))
|
||||
|
||||
header = NewHeader(emptyHandler, config.Headers{
|
||||
header = NewHeader(emptyHandler, dynamic.Headers{
|
||||
CustomRequestHeaders: map[string]string{
|
||||
"X-Custom-Request-Header": "",
|
||||
},
|
||||
|
@ -86,7 +86,7 @@ func TestSecureHeader(t *testing.T) {
|
|||
}
|
||||
|
||||
emptyHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})
|
||||
header, err := New(context.Background(), emptyHandler, config.Headers{
|
||||
header, err := New(context.Background(), emptyHandler, dynamic.Headers{
|
||||
AllowedHosts: []string{"foo.com", "bar.com"},
|
||||
}, "foo")
|
||||
require.NoError(t, err)
|
||||
|
@ -119,7 +119,7 @@ func TestSSLForceHost(t *testing.T) {
|
|||
{
|
||||
desc: "http should return a 301",
|
||||
host: "http://powpow.example.com",
|
||||
secureMiddleware: newSecure(next, config.Headers{
|
||||
secureMiddleware: newSecure(next, dynamic.Headers{
|
||||
SSLRedirect: true,
|
||||
SSLForceHost: true,
|
||||
SSLHost: "powpow.example.com",
|
||||
|
@ -129,7 +129,7 @@ func TestSSLForceHost(t *testing.T) {
|
|||
{
|
||||
desc: "http sub domain should return a 301",
|
||||
host: "http://www.powpow.example.com",
|
||||
secureMiddleware: newSecure(next, config.Headers{
|
||||
secureMiddleware: newSecure(next, dynamic.Headers{
|
||||
SSLRedirect: true,
|
||||
SSLForceHost: true,
|
||||
SSLHost: "powpow.example.com",
|
||||
|
@ -139,7 +139,7 @@ func TestSSLForceHost(t *testing.T) {
|
|||
{
|
||||
desc: "https should return a 200",
|
||||
host: "https://powpow.example.com",
|
||||
secureMiddleware: newSecure(next, config.Headers{
|
||||
secureMiddleware: newSecure(next, dynamic.Headers{
|
||||
SSLRedirect: true,
|
||||
SSLForceHost: true,
|
||||
SSLHost: "powpow.example.com",
|
||||
|
@ -149,7 +149,7 @@ func TestSSLForceHost(t *testing.T) {
|
|||
{
|
||||
desc: "https sub domain should return a 301",
|
||||
host: "https://www.powpow.example.com",
|
||||
secureMiddleware: newSecure(next, config.Headers{
|
||||
secureMiddleware: newSecure(next, dynamic.Headers{
|
||||
SSLRedirect: true,
|
||||
SSLForceHost: true,
|
||||
SSLHost: "powpow.example.com",
|
||||
|
@ -159,7 +159,7 @@ func TestSSLForceHost(t *testing.T) {
|
|||
{
|
||||
desc: "http without force host and sub domain should return a 301",
|
||||
host: "http://www.powpow.example.com",
|
||||
secureMiddleware: newSecure(next, config.Headers{
|
||||
secureMiddleware: newSecure(next, dynamic.Headers{
|
||||
SSLRedirect: true,
|
||||
SSLForceHost: false,
|
||||
SSLHost: "powpow.example.com",
|
||||
|
@ -169,7 +169,7 @@ func TestSSLForceHost(t *testing.T) {
|
|||
{
|
||||
desc: "https without force host and sub domain should return a 301",
|
||||
host: "https://www.powpow.example.com",
|
||||
secureMiddleware: newSecure(next, config.Headers{
|
||||
secureMiddleware: newSecure(next, dynamic.Headers{
|
||||
SSLRedirect: true,
|
||||
SSLForceHost: false,
|
||||
SSLHost: "powpow.example.com",
|
||||
|
@ -201,7 +201,7 @@ func TestCORSPreflights(t *testing.T) {
|
|||
}{
|
||||
{
|
||||
desc: "Test Simple Preflight",
|
||||
header: NewHeader(emptyHandler, config.Headers{
|
||||
header: NewHeader(emptyHandler, dynamic.Headers{
|
||||
AccessControlAllowMethods: []string{"GET", "OPTIONS", "PUT"},
|
||||
AccessControlAllowOrigin: "origin-list-or-null",
|
||||
AccessControlMaxAge: 600,
|
||||
|
@ -219,7 +219,7 @@ func TestCORSPreflights(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "Wildcard origin Preflight",
|
||||
header: NewHeader(emptyHandler, config.Headers{
|
||||
header: NewHeader(emptyHandler, dynamic.Headers{
|
||||
AccessControlAllowMethods: []string{"GET", "OPTIONS", "PUT"},
|
||||
AccessControlAllowOrigin: "*",
|
||||
AccessControlMaxAge: 600,
|
||||
|
@ -237,7 +237,7 @@ func TestCORSPreflights(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "Allow Credentials Preflight",
|
||||
header: NewHeader(emptyHandler, config.Headers{
|
||||
header: NewHeader(emptyHandler, dynamic.Headers{
|
||||
AccessControlAllowMethods: []string{"GET", "OPTIONS", "PUT"},
|
||||
AccessControlAllowOrigin: "*",
|
||||
AccessControlAllowCredentials: true,
|
||||
|
@ -257,7 +257,7 @@ func TestCORSPreflights(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "Allow Headers Preflight",
|
||||
header: NewHeader(emptyHandler, config.Headers{
|
||||
header: NewHeader(emptyHandler, dynamic.Headers{
|
||||
AccessControlAllowMethods: []string{"GET", "OPTIONS", "PUT"},
|
||||
AccessControlAllowOrigin: "*",
|
||||
AccessControlAllowHeaders: []string{"origin", "X-Forwarded-For"},
|
||||
|
@ -293,14 +293,14 @@ func TestCORSPreflights(t *testing.T) {
|
|||
func TestEmptyHeaderObject(t *testing.T) {
|
||||
next := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})
|
||||
|
||||
_, err := New(context.Background(), next, config.Headers{}, "testing")
|
||||
_, err := New(context.Background(), next, dynamic.Headers{}, "testing")
|
||||
require.Errorf(t, err, "headers configuration not valid")
|
||||
}
|
||||
|
||||
func TestCustomHeaderHandler(t *testing.T) {
|
||||
next := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})
|
||||
|
||||
header, _ := New(context.Background(), next, config.Headers{
|
||||
header, _ := New(context.Background(), next, dynamic.Headers{
|
||||
CustomRequestHeaders: map[string]string{
|
||||
"X-Custom-Request-Header": "test_request",
|
||||
},
|
||||
|
@ -342,7 +342,7 @@ func TestCORSResponses(t *testing.T) {
|
|||
}{
|
||||
{
|
||||
desc: "Test Simple Request",
|
||||
header: NewHeader(emptyHandler, config.Headers{
|
||||
header: NewHeader(emptyHandler, dynamic.Headers{
|
||||
AccessControlAllowOrigin: "origin-list-or-null",
|
||||
}),
|
||||
requestHeaders: map[string][]string{
|
||||
|
@ -354,7 +354,7 @@ func TestCORSResponses(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "Wildcard origin Request",
|
||||
header: NewHeader(emptyHandler, config.Headers{
|
||||
header: NewHeader(emptyHandler, dynamic.Headers{
|
||||
AccessControlAllowOrigin: "*",
|
||||
}),
|
||||
requestHeaders: map[string][]string{
|
||||
|
@ -366,7 +366,7 @@ func TestCORSResponses(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "Empty origin Request",
|
||||
header: NewHeader(emptyHandler, config.Headers{
|
||||
header: NewHeader(emptyHandler, dynamic.Headers{
|
||||
AccessControlAllowOrigin: "origin-list-or-null",
|
||||
}),
|
||||
requestHeaders: map[string][]string{},
|
||||
|
@ -376,13 +376,13 @@ func TestCORSResponses(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "Not Defined origin Request",
|
||||
header: NewHeader(emptyHandler, config.Headers{}),
|
||||
header: NewHeader(emptyHandler, dynamic.Headers{}),
|
||||
requestHeaders: map[string][]string{},
|
||||
expected: map[string][]string{},
|
||||
},
|
||||
{
|
||||
desc: "Allow Credentials Request",
|
||||
header: NewHeader(emptyHandler, config.Headers{
|
||||
header: NewHeader(emptyHandler, dynamic.Headers{
|
||||
AccessControlAllowOrigin: "*",
|
||||
AccessControlAllowCredentials: true,
|
||||
}),
|
||||
|
@ -396,7 +396,7 @@ func TestCORSResponses(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "Expose Headers Request",
|
||||
header: NewHeader(emptyHandler, config.Headers{
|
||||
header: NewHeader(emptyHandler, dynamic.Headers{
|
||||
AccessControlAllowOrigin: "*",
|
||||
AccessControlExposeHeaders: []string{"origin", "X-Forwarded-For"},
|
||||
}),
|
||||
|
@ -410,7 +410,7 @@ func TestCORSResponses(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "Test Simple Request with Vary Headers",
|
||||
header: NewHeader(emptyHandler, config.Headers{
|
||||
header: NewHeader(emptyHandler, dynamic.Headers{
|
||||
AccessControlAllowOrigin: "origin-list-or-null",
|
||||
AddVaryHeader: true,
|
||||
}),
|
||||
|
@ -424,7 +424,7 @@ func TestCORSResponses(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "Test Simple Request with Vary Headers and non-empty response",
|
||||
header: NewHeader(nonEmptyHandler, config.Headers{
|
||||
header: NewHeader(nonEmptyHandler, dynamic.Headers{
|
||||
AccessControlAllowOrigin: "origin-list-or-null",
|
||||
AddVaryHeader: true,
|
||||
}),
|
||||
|
@ -462,7 +462,7 @@ func TestCustomResponseHeaders(t *testing.T) {
|
|||
}{
|
||||
{
|
||||
desc: "Test Simple Response",
|
||||
header: NewHeader(emptyHandler, config.Headers{
|
||||
header: NewHeader(emptyHandler, dynamic.Headers{
|
||||
CustomResponseHeaders: map[string]string{
|
||||
"Testing": "foo",
|
||||
"Testing2": "bar",
|
||||
|
@ -475,7 +475,7 @@ func TestCustomResponseHeaders(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "Deleting Custom Header",
|
||||
header: NewHeader(emptyHandler, config.Headers{
|
||||
header: NewHeader(emptyHandler, dynamic.Headers{
|
||||
CustomResponseHeaders: map[string]string{
|
||||
"Testing": "foo",
|
||||
"Testing2": "",
|
||||
|
|
|
@ -6,7 +6,7 @@ import (
|
|||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/containous/traefik/pkg/config"
|
||||
"github.com/containous/traefik/pkg/config/dynamic"
|
||||
"github.com/containous/traefik/pkg/ip"
|
||||
"github.com/containous/traefik/pkg/middlewares"
|
||||
"github.com/containous/traefik/pkg/tracing"
|
||||
|
@ -27,7 +27,7 @@ type ipWhiteLister struct {
|
|||
}
|
||||
|
||||
// New builds a new IPWhiteLister given a list of CIDR-Strings to whitelist
|
||||
func New(ctx context.Context, next http.Handler, config config.IPWhiteList, name string) (http.Handler, error) {
|
||||
func New(ctx context.Context, next http.Handler, config dynamic.IPWhiteList, name string) (http.Handler, error) {
|
||||
logger := middlewares.GetLogger(ctx, name, typeName)
|
||||
logger.Debug("Creating middleware")
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ import (
|
|||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"github.com/containous/traefik/pkg/config"
|
||||
"github.com/containous/traefik/pkg/config/dynamic"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
@ -14,19 +14,19 @@ import (
|
|||
func TestNewIPWhiteLister(t *testing.T) {
|
||||
testCases := []struct {
|
||||
desc string
|
||||
whiteList config.IPWhiteList
|
||||
whiteList dynamic.IPWhiteList
|
||||
expectedError bool
|
||||
}{
|
||||
{
|
||||
desc: "invalid IP",
|
||||
whiteList: config.IPWhiteList{
|
||||
whiteList: dynamic.IPWhiteList{
|
||||
SourceRange: []string{"foo"},
|
||||
},
|
||||
expectedError: true,
|
||||
},
|
||||
{
|
||||
desc: "valid IP",
|
||||
whiteList: config.IPWhiteList{
|
||||
whiteList: dynamic.IPWhiteList{
|
||||
SourceRange: []string{"10.10.10.10"},
|
||||
},
|
||||
},
|
||||
|
@ -53,13 +53,13 @@ func TestNewIPWhiteLister(t *testing.T) {
|
|||
func TestIPWhiteLister_ServeHTTP(t *testing.T) {
|
||||
testCases := []struct {
|
||||
desc string
|
||||
whiteList config.IPWhiteList
|
||||
whiteList dynamic.IPWhiteList
|
||||
remoteAddr string
|
||||
expected int
|
||||
}{
|
||||
{
|
||||
desc: "authorized with remote address",
|
||||
whiteList: config.IPWhiteList{
|
||||
whiteList: dynamic.IPWhiteList{
|
||||
SourceRange: []string{"20.20.20.20"},
|
||||
},
|
||||
remoteAddr: "20.20.20.20:1234",
|
||||
|
@ -67,7 +67,7 @@ func TestIPWhiteLister_ServeHTTP(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "non authorized with remote address",
|
||||
whiteList: config.IPWhiteList{
|
||||
whiteList: dynamic.IPWhiteList{
|
||||
SourceRange: []string{"20.20.20.20"},
|
||||
},
|
||||
remoteAddr: "20.20.20.21:1234",
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/containous/traefik/pkg/config"
|
||||
"github.com/containous/traefik/pkg/config/dynamic"
|
||||
"github.com/containous/traefik/pkg/middlewares"
|
||||
"github.com/containous/traefik/pkg/tracing"
|
||||
"github.com/opentracing/opentracing-go/ext"
|
||||
|
@ -23,7 +23,7 @@ type maxConnection struct {
|
|||
}
|
||||
|
||||
// New creates a max connection middleware.
|
||||
func New(ctx context.Context, next http.Handler, maxConns config.MaxConn, name string) (http.Handler, error) {
|
||||
func New(ctx context.Context, next http.Handler, maxConns dynamic.MaxConn, name string) (http.Handler, error) {
|
||||
middlewares.GetLogger(ctx, name, typeName).Debug("Creating middleware")
|
||||
|
||||
extractFunc, err := utils.NewExtractor(maxConns.ExtractorFunc)
|
||||
|
|
|
@ -11,7 +11,7 @@ import (
|
|||
"net/url"
|
||||
"strings"
|
||||
|
||||
"github.com/containous/traefik/pkg/config"
|
||||
"github.com/containous/traefik/pkg/config/dynamic"
|
||||
"github.com/containous/traefik/pkg/log"
|
||||
"github.com/containous/traefik/pkg/middlewares"
|
||||
"github.com/containous/traefik/pkg/tracing"
|
||||
|
@ -40,7 +40,7 @@ type DistinguishedNameOptions struct {
|
|||
StateOrProvinceName bool
|
||||
}
|
||||
|
||||
func newDistinguishedNameOptions(info *config.TLSCLientCertificateDNInfo) *DistinguishedNameOptions {
|
||||
func newDistinguishedNameOptions(info *dynamic.TLSCLientCertificateDNInfo) *DistinguishedNameOptions {
|
||||
if info == nil {
|
||||
return nil
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ type passTLSClientCert struct {
|
|||
}
|
||||
|
||||
// New constructs a new PassTLSClientCert instance from supplied frontend header struct.
|
||||
func New(ctx context.Context, next http.Handler, config config.PassTLSClientCert, name string) (http.Handler, error) {
|
||||
func New(ctx context.Context, next http.Handler, config dynamic.PassTLSClientCert, name string) (http.Handler, error) {
|
||||
middlewares.GetLogger(ctx, name, typeName).Debug("Creating middleware")
|
||||
|
||||
return &passTLSClientCert{
|
||||
|
@ -85,7 +85,7 @@ type tlsClientCertificateInfo struct {
|
|||
issuer *DistinguishedNameOptions
|
||||
}
|
||||
|
||||
func newTLSClientInfo(info *config.TLSClientCertificateInfo) *tlsClientCertificateInfo {
|
||||
func newTLSClientInfo(info *dynamic.TLSClientCertificateInfo) *tlsClientCertificateInfo {
|
||||
if info == nil {
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ import (
|
|||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/containous/traefik/pkg/config"
|
||||
"github.com/containous/traefik/pkg/config/dynamic"
|
||||
"github.com/containous/traefik/pkg/testhelpers"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
@ -367,7 +367,7 @@ func TestTLSClientHeadersWithPEM(t *testing.T) {
|
|||
testCases := []struct {
|
||||
desc string
|
||||
certContents []string // set the request TLS attribute if defined
|
||||
config config.PassTLSClientCert
|
||||
config dynamic.PassTLSClientCert
|
||||
expectedHeader string
|
||||
}{
|
||||
{
|
||||
|
@ -379,24 +379,24 @@ func TestTLSClientHeadersWithPEM(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "No TLS, with pem option true",
|
||||
config: config.PassTLSClientCert{PEM: true},
|
||||
config: dynamic.PassTLSClientCert{PEM: true},
|
||||
},
|
||||
{
|
||||
desc: "TLS with simple certificate, with pem option true",
|
||||
certContents: []string{minimalCheeseCrt},
|
||||
config: config.PassTLSClientCert{PEM: true},
|
||||
config: dynamic.PassTLSClientCert{PEM: true},
|
||||
expectedHeader: getCleanCertContents([]string{minimalCert}),
|
||||
},
|
||||
{
|
||||
desc: "TLS with complete certificate, with pem option true",
|
||||
certContents: []string{minimalCheeseCrt},
|
||||
config: config.PassTLSClientCert{PEM: true},
|
||||
config: dynamic.PassTLSClientCert{PEM: true},
|
||||
expectedHeader: getCleanCertContents([]string{minimalCheeseCrt}),
|
||||
},
|
||||
{
|
||||
desc: "TLS with two certificate, with pem option true",
|
||||
certContents: []string{minimalCert, minimalCheeseCrt},
|
||||
config: config.PassTLSClientCert{PEM: true},
|
||||
config: dynamic.PassTLSClientCert{PEM: true},
|
||||
expectedHeader: getCleanCertContents([]string{minimalCert, minimalCheeseCrt}),
|
||||
},
|
||||
}
|
||||
|
@ -488,7 +488,7 @@ func TestTLSClientHeadersWithCertInfo(t *testing.T) {
|
|||
testCases := []struct {
|
||||
desc string
|
||||
certContents []string // set the request TLS attribute if defined
|
||||
config config.PassTLSClientCert
|
||||
config dynamic.PassTLSClientCert
|
||||
expectedHeader string
|
||||
}{
|
||||
{
|
||||
|
@ -500,9 +500,9 @@ func TestTLSClientHeadersWithCertInfo(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "No TLS, with subject info",
|
||||
config: config.PassTLSClientCert{
|
||||
Info: &config.TLSClientCertificateInfo{
|
||||
Subject: &config.TLSCLientCertificateDNInfo{
|
||||
config: dynamic.PassTLSClientCert{
|
||||
Info: &dynamic.TLSClientCertificateInfo{
|
||||
Subject: &dynamic.TLSCLientCertificateDNInfo{
|
||||
CommonName: true,
|
||||
Organization: true,
|
||||
Locality: true,
|
||||
|
@ -515,22 +515,22 @@ func TestTLSClientHeadersWithCertInfo(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "No TLS, with pem option false with empty subject info",
|
||||
config: config.PassTLSClientCert{
|
||||
config: dynamic.PassTLSClientCert{
|
||||
PEM: false,
|
||||
Info: &config.TLSClientCertificateInfo{
|
||||
Subject: &config.TLSCLientCertificateDNInfo{},
|
||||
Info: &dynamic.TLSClientCertificateInfo{
|
||||
Subject: &dynamic.TLSCLientCertificateDNInfo{},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "TLS with simple certificate, with all info",
|
||||
certContents: []string{minimalCheeseCrt},
|
||||
config: config.PassTLSClientCert{
|
||||
Info: &config.TLSClientCertificateInfo{
|
||||
config: dynamic.PassTLSClientCert{
|
||||
Info: &dynamic.TLSClientCertificateInfo{
|
||||
NotAfter: true,
|
||||
NotBefore: true,
|
||||
Sans: true,
|
||||
Subject: &config.TLSCLientCertificateDNInfo{
|
||||
Subject: &dynamic.TLSCLientCertificateDNInfo{
|
||||
CommonName: true,
|
||||
Country: true,
|
||||
DomainComponent: true,
|
||||
|
@ -539,7 +539,7 @@ func TestTLSClientHeadersWithCertInfo(t *testing.T) {
|
|||
Province: true,
|
||||
SerialNumber: true,
|
||||
},
|
||||
Issuer: &config.TLSCLientCertificateDNInfo{
|
||||
Issuer: &dynamic.TLSCLientCertificateDNInfo{
|
||||
CommonName: true,
|
||||
Country: true,
|
||||
DomainComponent: true,
|
||||
|
@ -555,14 +555,14 @@ func TestTLSClientHeadersWithCertInfo(t *testing.T) {
|
|||
{
|
||||
desc: "TLS with simple certificate, with some info",
|
||||
certContents: []string{minimalCheeseCrt},
|
||||
config: config.PassTLSClientCert{
|
||||
Info: &config.TLSClientCertificateInfo{
|
||||
config: dynamic.PassTLSClientCert{
|
||||
Info: &dynamic.TLSClientCertificateInfo{
|
||||
NotAfter: true,
|
||||
Sans: true,
|
||||
Subject: &config.TLSCLientCertificateDNInfo{
|
||||
Subject: &dynamic.TLSCLientCertificateDNInfo{
|
||||
Organization: true,
|
||||
},
|
||||
Issuer: &config.TLSCLientCertificateDNInfo{
|
||||
Issuer: &dynamic.TLSCLientCertificateDNInfo{
|
||||
Country: true,
|
||||
},
|
||||
},
|
||||
|
@ -572,12 +572,12 @@ func TestTLSClientHeadersWithCertInfo(t *testing.T) {
|
|||
{
|
||||
desc: "TLS with complete certificate, with all info",
|
||||
certContents: []string{completeCheeseCrt},
|
||||
config: config.PassTLSClientCert{
|
||||
Info: &config.TLSClientCertificateInfo{
|
||||
config: dynamic.PassTLSClientCert{
|
||||
Info: &dynamic.TLSClientCertificateInfo{
|
||||
NotAfter: true,
|
||||
NotBefore: true,
|
||||
Sans: true,
|
||||
Subject: &config.TLSCLientCertificateDNInfo{
|
||||
Subject: &dynamic.TLSCLientCertificateDNInfo{
|
||||
Country: true,
|
||||
Province: true,
|
||||
Locality: true,
|
||||
|
@ -586,7 +586,7 @@ func TestTLSClientHeadersWithCertInfo(t *testing.T) {
|
|||
SerialNumber: true,
|
||||
DomainComponent: true,
|
||||
},
|
||||
Issuer: &config.TLSCLientCertificateDNInfo{
|
||||
Issuer: &dynamic.TLSCLientCertificateDNInfo{
|
||||
Country: true,
|
||||
Province: true,
|
||||
Locality: true,
|
||||
|
@ -602,12 +602,12 @@ func TestTLSClientHeadersWithCertInfo(t *testing.T) {
|
|||
{
|
||||
desc: "TLS with 2 certificates, with all info",
|
||||
certContents: []string{minimalCheeseCrt, completeCheeseCrt},
|
||||
config: config.PassTLSClientCert{
|
||||
Info: &config.TLSClientCertificateInfo{
|
||||
config: dynamic.PassTLSClientCert{
|
||||
Info: &dynamic.TLSClientCertificateInfo{
|
||||
NotAfter: true,
|
||||
NotBefore: true,
|
||||
Sans: true,
|
||||
Subject: &config.TLSCLientCertificateDNInfo{
|
||||
Subject: &dynamic.TLSCLientCertificateDNInfo{
|
||||
Country: true,
|
||||
Province: true,
|
||||
Locality: true,
|
||||
|
@ -616,7 +616,7 @@ func TestTLSClientHeadersWithCertInfo(t *testing.T) {
|
|||
SerialNumber: true,
|
||||
DomainComponent: true,
|
||||
},
|
||||
Issuer: &config.TLSCLientCertificateDNInfo{
|
||||
Issuer: &dynamic.TLSCLientCertificateDNInfo{
|
||||
Country: true,
|
||||
Province: true,
|
||||
Locality: true,
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/containous/traefik/pkg/config"
|
||||
"github.com/containous/traefik/pkg/config/dynamic"
|
||||
"github.com/containous/traefik/pkg/middlewares"
|
||||
"github.com/containous/traefik/pkg/tracing"
|
||||
"github.com/opentracing/opentracing-go/ext"
|
||||
|
@ -23,7 +23,7 @@ type rateLimiter struct {
|
|||
}
|
||||
|
||||
// New creates rate limiter middleware.
|
||||
func New(ctx context.Context, next http.Handler, config config.RateLimit, name string) (http.Handler, error) {
|
||||
func New(ctx context.Context, next http.Handler, config dynamic.RateLimit, name string) (http.Handler, error) {
|
||||
middlewares.GetLogger(ctx, name, typeName).Debug("Creating middleware")
|
||||
|
||||
extractFunc, err := utils.NewExtractor(config.ExtractorFunc)
|
||||
|
|
|
@ -4,7 +4,7 @@ import (
|
|||
"context"
|
||||
"net/http"
|
||||
|
||||
"github.com/containous/traefik/pkg/config"
|
||||
"github.com/containous/traefik/pkg/config/dynamic"
|
||||
"github.com/containous/traefik/pkg/middlewares"
|
||||
)
|
||||
|
||||
|
@ -13,7 +13,7 @@ const (
|
|||
)
|
||||
|
||||
// NewRedirectRegex creates a redirect middleware.
|
||||
func NewRedirectRegex(ctx context.Context, next http.Handler, conf config.RedirectRegex, name string) (http.Handler, error) {
|
||||
func NewRedirectRegex(ctx context.Context, next http.Handler, conf dynamic.RedirectRegex, name string) (http.Handler, error) {
|
||||
logger := middlewares.GetLogger(ctx, name, typeRegexName)
|
||||
logger.Debug("Creating middleware")
|
||||
logger.Debugf("Setting up redirection from %s to %s", conf.Regex, conf.Replacement)
|
||||
|
|
|
@ -7,7 +7,7 @@ import (
|
|||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"github.com/containous/traefik/pkg/config"
|
||||
"github.com/containous/traefik/pkg/config/dynamic"
|
||||
"github.com/containous/traefik/pkg/testhelpers"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
@ -16,7 +16,7 @@ import (
|
|||
func TestRedirectRegexHandler(t *testing.T) {
|
||||
testCases := []struct {
|
||||
desc string
|
||||
config config.RedirectRegex
|
||||
config dynamic.RedirectRegex
|
||||
method string
|
||||
url string
|
||||
secured bool
|
||||
|
@ -26,7 +26,7 @@ func TestRedirectRegexHandler(t *testing.T) {
|
|||
}{
|
||||
{
|
||||
desc: "simple redirection",
|
||||
config: config.RedirectRegex{
|
||||
config: dynamic.RedirectRegex{
|
||||
Regex: `^(?:http?:\/\/)(foo)(\.com)(:\d+)(.*)$`,
|
||||
Replacement: "https://${1}bar$2:443$4",
|
||||
},
|
||||
|
@ -36,7 +36,7 @@ func TestRedirectRegexHandler(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "use request header",
|
||||
config: config.RedirectRegex{
|
||||
config: dynamic.RedirectRegex{
|
||||
Regex: `^(?:http?:\/\/)(foo)(\.com)(:\d+)(.*)$`,
|
||||
Replacement: `https://${1}{{ .Request.Header.Get "X-Foo" }}$2:443$4`,
|
||||
},
|
||||
|
@ -46,7 +46,7 @@ func TestRedirectRegexHandler(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "URL doesn't match regex",
|
||||
config: config.RedirectRegex{
|
||||
config: dynamic.RedirectRegex{
|
||||
Regex: `^(?:http?:\/\/)(foo)(\.com)(:\d+)(.*)$`,
|
||||
Replacement: "https://${1}bar$2:443$4",
|
||||
},
|
||||
|
@ -55,7 +55,7 @@ func TestRedirectRegexHandler(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "invalid rewritten URL",
|
||||
config: config.RedirectRegex{
|
||||
config: dynamic.RedirectRegex{
|
||||
Regex: `^(.*)$`,
|
||||
Replacement: "http://192.168.0.%31/",
|
||||
},
|
||||
|
@ -64,7 +64,7 @@ func TestRedirectRegexHandler(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "invalid regex",
|
||||
config: config.RedirectRegex{
|
||||
config: dynamic.RedirectRegex{
|
||||
Regex: `^(.*`,
|
||||
Replacement: "$1",
|
||||
},
|
||||
|
@ -73,7 +73,7 @@ func TestRedirectRegexHandler(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "HTTP to HTTPS permanent",
|
||||
config: config.RedirectRegex{
|
||||
config: dynamic.RedirectRegex{
|
||||
Regex: `^http://`,
|
||||
Replacement: "https://$1",
|
||||
Permanent: true,
|
||||
|
@ -84,7 +84,7 @@ func TestRedirectRegexHandler(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "HTTPS to HTTP permanent",
|
||||
config: config.RedirectRegex{
|
||||
config: dynamic.RedirectRegex{
|
||||
Regex: `https://foo`,
|
||||
Replacement: "http://foo",
|
||||
Permanent: true,
|
||||
|
@ -96,7 +96,7 @@ func TestRedirectRegexHandler(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "HTTP to HTTPS",
|
||||
config: config.RedirectRegex{
|
||||
config: dynamic.RedirectRegex{
|
||||
Regex: `http://foo:80`,
|
||||
Replacement: "https://foo:443",
|
||||
},
|
||||
|
@ -106,7 +106,7 @@ func TestRedirectRegexHandler(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "HTTPS to HTTP",
|
||||
config: config.RedirectRegex{
|
||||
config: dynamic.RedirectRegex{
|
||||
Regex: `https://foo:443`,
|
||||
Replacement: "http://foo:80",
|
||||
},
|
||||
|
@ -117,7 +117,7 @@ func TestRedirectRegexHandler(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "HTTP to HTTP",
|
||||
config: config.RedirectRegex{
|
||||
config: dynamic.RedirectRegex{
|
||||
Regex: `http://foo:80`,
|
||||
Replacement: "http://foo:88",
|
||||
},
|
||||
|
@ -127,7 +127,7 @@ func TestRedirectRegexHandler(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "HTTP to HTTP POST",
|
||||
config: config.RedirectRegex{
|
||||
config: dynamic.RedirectRegex{
|
||||
Regex: `^http://`,
|
||||
Replacement: "https://$1",
|
||||
},
|
||||
|
@ -138,7 +138,7 @@ func TestRedirectRegexHandler(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "HTTP to HTTP POST permanent",
|
||||
config: config.RedirectRegex{
|
||||
config: dynamic.RedirectRegex{
|
||||
Regex: `^http://`,
|
||||
Replacement: "https://$1",
|
||||
Permanent: true,
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/containous/traefik/pkg/config"
|
||||
"github.com/containous/traefik/pkg/config/dynamic"
|
||||
"github.com/containous/traefik/pkg/middlewares"
|
||||
)
|
||||
|
||||
|
@ -15,7 +15,7 @@ const (
|
|||
)
|
||||
|
||||
// NewRedirectScheme creates a new RedirectScheme middleware.
|
||||
func NewRedirectScheme(ctx context.Context, next http.Handler, conf config.RedirectScheme, name string) (http.Handler, error) {
|
||||
func NewRedirectScheme(ctx context.Context, next http.Handler, conf dynamic.RedirectScheme, name string) (http.Handler, error) {
|
||||
logger := middlewares.GetLogger(ctx, name, typeSchemeName)
|
||||
logger.Debug("Creating middleware")
|
||||
logger.Debugf("Setting up redirection to %s %s", conf.Scheme, conf.Port)
|
||||
|
|
|
@ -8,7 +8,7 @@ import (
|
|||
"regexp"
|
||||
"testing"
|
||||
|
||||
"github.com/containous/traefik/pkg/config"
|
||||
"github.com/containous/traefik/pkg/config/dynamic"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
@ -16,7 +16,7 @@ import (
|
|||
func TestRedirectSchemeHandler(t *testing.T) {
|
||||
testCases := []struct {
|
||||
desc string
|
||||
config config.RedirectScheme
|
||||
config dynamic.RedirectScheme
|
||||
method string
|
||||
url string
|
||||
secured bool
|
||||
|
@ -26,13 +26,13 @@ func TestRedirectSchemeHandler(t *testing.T) {
|
|||
}{
|
||||
{
|
||||
desc: "Without scheme",
|
||||
config: config.RedirectScheme{},
|
||||
config: dynamic.RedirectScheme{},
|
||||
url: "http://foo",
|
||||
errorExpected: true,
|
||||
},
|
||||
{
|
||||
desc: "HTTP to HTTPS",
|
||||
config: config.RedirectScheme{
|
||||
config: dynamic.RedirectScheme{
|
||||
Scheme: "https",
|
||||
},
|
||||
url: "http://foo",
|
||||
|
@ -41,7 +41,7 @@ func TestRedirectSchemeHandler(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "HTTP with port to HTTPS without port",
|
||||
config: config.RedirectScheme{
|
||||
config: dynamic.RedirectScheme{
|
||||
Scheme: "https",
|
||||
},
|
||||
url: "http://foo:8080",
|
||||
|
@ -50,7 +50,7 @@ func TestRedirectSchemeHandler(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "HTTP without port to HTTPS with port",
|
||||
config: config.RedirectScheme{
|
||||
config: dynamic.RedirectScheme{
|
||||
Scheme: "https",
|
||||
Port: "8443",
|
||||
},
|
||||
|
@ -60,7 +60,7 @@ func TestRedirectSchemeHandler(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "HTTP with port to HTTPS with port",
|
||||
config: config.RedirectScheme{
|
||||
config: dynamic.RedirectScheme{
|
||||
Scheme: "https",
|
||||
Port: "8443",
|
||||
},
|
||||
|
@ -70,7 +70,7 @@ func TestRedirectSchemeHandler(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "HTTPS with port to HTTPS with port",
|
||||
config: config.RedirectScheme{
|
||||
config: dynamic.RedirectScheme{
|
||||
Scheme: "https",
|
||||
Port: "8443",
|
||||
},
|
||||
|
@ -80,7 +80,7 @@ func TestRedirectSchemeHandler(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "HTTPS with port to HTTPS without port",
|
||||
config: config.RedirectScheme{
|
||||
config: dynamic.RedirectScheme{
|
||||
Scheme: "https",
|
||||
},
|
||||
url: "https://foo:8000",
|
||||
|
@ -89,7 +89,7 @@ func TestRedirectSchemeHandler(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "redirection to HTTPS without port from an URL already in https",
|
||||
config: config.RedirectScheme{
|
||||
config: dynamic.RedirectScheme{
|
||||
Scheme: "https",
|
||||
},
|
||||
url: "https://foo:8000/theother",
|
||||
|
@ -98,7 +98,7 @@ func TestRedirectSchemeHandler(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "HTTP to HTTPS permanent",
|
||||
config: config.RedirectScheme{
|
||||
config: dynamic.RedirectScheme{
|
||||
Scheme: "https",
|
||||
Port: "8443",
|
||||
Permanent: true,
|
||||
|
@ -109,7 +109,7 @@ func TestRedirectSchemeHandler(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "to HTTP 80",
|
||||
config: config.RedirectScheme{
|
||||
config: dynamic.RedirectScheme{
|
||||
Scheme: "http",
|
||||
Port: "80",
|
||||
},
|
||||
|
@ -119,7 +119,7 @@ func TestRedirectSchemeHandler(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "HTTP to wss",
|
||||
config: config.RedirectScheme{
|
||||
config: dynamic.RedirectScheme{
|
||||
Scheme: "wss",
|
||||
Port: "9443",
|
||||
},
|
||||
|
@ -129,7 +129,7 @@ func TestRedirectSchemeHandler(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "HTTP to wss without port",
|
||||
config: config.RedirectScheme{
|
||||
config: dynamic.RedirectScheme{
|
||||
Scheme: "wss",
|
||||
},
|
||||
url: "http://foo",
|
||||
|
@ -138,7 +138,7 @@ func TestRedirectSchemeHandler(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "HTTP with port to wss without port",
|
||||
config: config.RedirectScheme{
|
||||
config: dynamic.RedirectScheme{
|
||||
Scheme: "wss",
|
||||
},
|
||||
url: "http://foo:5678",
|
||||
|
@ -147,7 +147,7 @@ func TestRedirectSchemeHandler(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "HTTP to HTTPS without port",
|
||||
config: config.RedirectScheme{
|
||||
config: dynamic.RedirectScheme{
|
||||
Scheme: "https",
|
||||
},
|
||||
url: "http://foo:443",
|
||||
|
@ -156,7 +156,7 @@ func TestRedirectSchemeHandler(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "HTTP port redirection",
|
||||
config: config.RedirectScheme{
|
||||
config: dynamic.RedirectScheme{
|
||||
Scheme: "http",
|
||||
Port: "8181",
|
||||
},
|
||||
|
@ -166,7 +166,7 @@ func TestRedirectSchemeHandler(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "HTTPS with port 80 to HTTPS without port",
|
||||
config: config.RedirectScheme{
|
||||
config: dynamic.RedirectScheme{
|
||||
Scheme: "https",
|
||||
},
|
||||
url: "https://foo:80",
|
||||
|
|
|
@ -4,7 +4,7 @@ import (
|
|||
"context"
|
||||
"net/http"
|
||||
|
||||
"github.com/containous/traefik/pkg/config"
|
||||
"github.com/containous/traefik/pkg/config/dynamic"
|
||||
"github.com/containous/traefik/pkg/middlewares"
|
||||
"github.com/containous/traefik/pkg/tracing"
|
||||
"github.com/opentracing/opentracing-go/ext"
|
||||
|
@ -24,7 +24,7 @@ type replacePath struct {
|
|||
}
|
||||
|
||||
// New creates a new replace path middleware.
|
||||
func New(ctx context.Context, next http.Handler, config config.ReplacePath, name string) (http.Handler, error) {
|
||||
func New(ctx context.Context, next http.Handler, config dynamic.ReplacePath, name string) (http.Handler, error) {
|
||||
middlewares.GetLogger(ctx, name, typeName).Debug("Creating middleware")
|
||||
|
||||
return &replacePath{
|
||||
|
|
|
@ -5,14 +5,14 @@ import (
|
|||
"net/http"
|
||||
"testing"
|
||||
|
||||
"github.com/containous/traefik/pkg/config"
|
||||
"github.com/containous/traefik/pkg/config/dynamic"
|
||||
"github.com/containous/traefik/pkg/testhelpers"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestReplacePath(t *testing.T) {
|
||||
var replacementConfig = config.ReplacePath{
|
||||
var replacementConfig = dynamic.ReplacePath{
|
||||
Path: "/replacement-path",
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ import (
|
|||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/containous/traefik/pkg/config"
|
||||
"github.com/containous/traefik/pkg/config/dynamic"
|
||||
"github.com/containous/traefik/pkg/middlewares"
|
||||
"github.com/containous/traefik/pkg/middlewares/replacepath"
|
||||
"github.com/containous/traefik/pkg/tracing"
|
||||
|
@ -27,7 +27,7 @@ type replacePathRegex struct {
|
|||
}
|
||||
|
||||
// New creates a new replace path regex middleware.
|
||||
func New(ctx context.Context, next http.Handler, config config.ReplacePathRegex, name string) (http.Handler, error) {
|
||||
func New(ctx context.Context, next http.Handler, config dynamic.ReplacePathRegex, name string) (http.Handler, error) {
|
||||
middlewares.GetLogger(ctx, name, typeName).Debug("Creating middleware")
|
||||
|
||||
exp, err := regexp.Compile(strings.TrimSpace(config.Regex))
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
"net/http"
|
||||
"testing"
|
||||
|
||||
"github.com/containous/traefik/pkg/config"
|
||||
"github.com/containous/traefik/pkg/config/dynamic"
|
||||
"github.com/containous/traefik/pkg/middlewares/replacepath"
|
||||
"github.com/containous/traefik/pkg/testhelpers"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
@ -16,7 +16,7 @@ func TestReplacePathRegex(t *testing.T) {
|
|||
testCases := []struct {
|
||||
desc string
|
||||
path string
|
||||
config config.ReplacePathRegex
|
||||
config dynamic.ReplacePathRegex
|
||||
expectedPath string
|
||||
expectedHeader string
|
||||
expectsError bool
|
||||
|
@ -24,7 +24,7 @@ func TestReplacePathRegex(t *testing.T) {
|
|||
{
|
||||
desc: "simple regex",
|
||||
path: "/whoami/and/whoami",
|
||||
config: config.ReplacePathRegex{
|
||||
config: dynamic.ReplacePathRegex{
|
||||
Replacement: "/who-am-i/$1",
|
||||
Regex: `^/whoami/(.*)`,
|
||||
},
|
||||
|
@ -34,7 +34,7 @@ func TestReplacePathRegex(t *testing.T) {
|
|||
{
|
||||
desc: "simple replace (no regex)",
|
||||
path: "/whoami/and/whoami",
|
||||
config: config.ReplacePathRegex{
|
||||
config: dynamic.ReplacePathRegex{
|
||||
Replacement: "/who-am-i",
|
||||
Regex: `/whoami`,
|
||||
},
|
||||
|
@ -44,7 +44,7 @@ func TestReplacePathRegex(t *testing.T) {
|
|||
{
|
||||
desc: "no match",
|
||||
path: "/whoami/and/whoami",
|
||||
config: config.ReplacePathRegex{
|
||||
config: dynamic.ReplacePathRegex{
|
||||
Replacement: "/whoami",
|
||||
Regex: `/no-match`,
|
||||
},
|
||||
|
@ -53,7 +53,7 @@ func TestReplacePathRegex(t *testing.T) {
|
|||
{
|
||||
desc: "multiple replacement",
|
||||
path: "/downloads/src/source.go",
|
||||
config: config.ReplacePathRegex{
|
||||
config: dynamic.ReplacePathRegex{
|
||||
Replacement: "/downloads/$1-$2",
|
||||
Regex: `^(?i)/downloads/([^/]+)/([^/]+)$`,
|
||||
},
|
||||
|
@ -63,7 +63,7 @@ func TestReplacePathRegex(t *testing.T) {
|
|||
{
|
||||
desc: "invalid regular expression",
|
||||
path: "/invalid/regexp/test",
|
||||
config: config.ReplacePathRegex{
|
||||
config: dynamic.ReplacePathRegex{
|
||||
Replacement: "/valid/regexp/$1",
|
||||
Regex: `^(?err)/invalid/regexp/([^/]+)$`,
|
||||
},
|
||||
|
|
|
@ -9,7 +9,7 @@ import (
|
|||
"net/http"
|
||||
"net/http/httptrace"
|
||||
|
||||
"github.com/containous/traefik/pkg/config"
|
||||
"github.com/containous/traefik/pkg/config/dynamic"
|
||||
"github.com/containous/traefik/pkg/middlewares"
|
||||
"github.com/containous/traefik/pkg/tracing"
|
||||
"github.com/opentracing/opentracing-go/ext"
|
||||
|
@ -42,7 +42,7 @@ type retry struct {
|
|||
}
|
||||
|
||||
// New returns a new retry middleware.
|
||||
func New(ctx context.Context, next http.Handler, config config.Retry, listener Listener, name string) (http.Handler, error) {
|
||||
func New(ctx context.Context, next http.Handler, config dynamic.Retry, listener Listener, name string) (http.Handler, error) {
|
||||
logger := middlewares.GetLogger(ctx, name, typeName)
|
||||
logger.Debug("Creating middleware")
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ import (
|
|||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/containous/traefik/pkg/config"
|
||||
"github.com/containous/traefik/pkg/config/dynamic"
|
||||
"github.com/containous/traefik/pkg/middlewares/emptybackendhandler"
|
||||
"github.com/containous/traefik/pkg/testhelpers"
|
||||
"github.com/gorilla/websocket"
|
||||
|
@ -22,42 +22,42 @@ import (
|
|||
func TestRetry(t *testing.T) {
|
||||
testCases := []struct {
|
||||
desc string
|
||||
config config.Retry
|
||||
config dynamic.Retry
|
||||
wantRetryAttempts int
|
||||
wantResponseStatus int
|
||||
amountFaultyEndpoints int
|
||||
}{
|
||||
{
|
||||
desc: "no retry on success",
|
||||
config: config.Retry{Attempts: 1},
|
||||
config: dynamic.Retry{Attempts: 1},
|
||||
wantRetryAttempts: 0,
|
||||
wantResponseStatus: http.StatusOK,
|
||||
amountFaultyEndpoints: 0,
|
||||
},
|
||||
{
|
||||
desc: "no retry when max request attempts is one",
|
||||
config: config.Retry{Attempts: 1},
|
||||
config: dynamic.Retry{Attempts: 1},
|
||||
wantRetryAttempts: 0,
|
||||
wantResponseStatus: http.StatusInternalServerError,
|
||||
amountFaultyEndpoints: 1,
|
||||
},
|
||||
{
|
||||
desc: "one retry when one server is faulty",
|
||||
config: config.Retry{Attempts: 2},
|
||||
config: dynamic.Retry{Attempts: 2},
|
||||
wantRetryAttempts: 1,
|
||||
wantResponseStatus: http.StatusOK,
|
||||
amountFaultyEndpoints: 1,
|
||||
},
|
||||
{
|
||||
desc: "two retries when two servers are faulty",
|
||||
config: config.Retry{Attempts: 3},
|
||||
config: dynamic.Retry{Attempts: 3},
|
||||
wantRetryAttempts: 2,
|
||||
wantResponseStatus: http.StatusOK,
|
||||
amountFaultyEndpoints: 2,
|
||||
},
|
||||
{
|
||||
desc: "max attempts exhausted delivers the 5xx response",
|
||||
config: config.Retry{Attempts: 3},
|
||||
config: dynamic.Retry{Attempts: 3},
|
||||
wantRetryAttempts: 2,
|
||||
wantResponseStatus: http.StatusInternalServerError,
|
||||
amountFaultyEndpoints: 3,
|
||||
|
@ -124,7 +124,7 @@ func TestRetryEmptyServerList(t *testing.T) {
|
|||
next := emptybackendhandler.New(loadBalancer)
|
||||
|
||||
retryListener := &countingRetryListener{}
|
||||
retry, err := New(context.Background(), next, config.Retry{Attempts: 3}, retryListener, "traefikTest")
|
||||
retry, err := New(context.Background(), next, dynamic.Retry{Attempts: 3}, retryListener, "traefikTest")
|
||||
require.NoError(t, err)
|
||||
|
||||
recorder := httptest.NewRecorder()
|
||||
|
@ -172,7 +172,7 @@ func TestMultipleRetriesShouldNotLooseHeaders(t *testing.T) {
|
|||
rw.WriteHeader(http.StatusNoContent)
|
||||
})
|
||||
|
||||
retry, err := New(context.Background(), next, config.Retry{Attempts: 3}, &countingRetryListener{}, "traefikTest")
|
||||
retry, err := New(context.Background(), next, dynamic.Retry{Attempts: 3}, &countingRetryListener{}, "traefikTest")
|
||||
require.NoError(t, err)
|
||||
|
||||
responseRecorder := httptest.NewRecorder()
|
||||
|
@ -218,7 +218,7 @@ func TestRetryWithFlush(t *testing.T) {
|
|||
}
|
||||
})
|
||||
|
||||
retry, err := New(context.Background(), next, config.Retry{Attempts: 1}, &countingRetryListener{}, "traefikTest")
|
||||
retry, err := New(context.Background(), next, dynamic.Retry{Attempts: 1}, &countingRetryListener{}, "traefikTest")
|
||||
require.NoError(t, err)
|
||||
|
||||
responseRecorder := httptest.NewRecorder()
|
||||
|
@ -293,7 +293,7 @@ func TestRetryWebsocket(t *testing.T) {
|
|||
}
|
||||
|
||||
retryListener := &countingRetryListener{}
|
||||
retryH, err := New(context.Background(), loadBalancer, config.Retry{Attempts: test.maxRequestAttempts}, retryListener, "traefikTest")
|
||||
retryH, err := New(context.Background(), loadBalancer, dynamic.Retry{Attempts: test.maxRequestAttempts}, retryListener, "traefikTest")
|
||||
require.NoError(t, err)
|
||||
|
||||
retryServer := httptest.NewServer(retryH)
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/containous/traefik/pkg/config"
|
||||
"github.com/containous/traefik/pkg/config/dynamic"
|
||||
"github.com/containous/traefik/pkg/middlewares"
|
||||
"github.com/containous/traefik/pkg/tracing"
|
||||
"github.com/opentracing/opentracing-go/ext"
|
||||
|
@ -25,7 +25,7 @@ type stripPrefix struct {
|
|||
}
|
||||
|
||||
// New creates a new strip prefix middleware.
|
||||
func New(ctx context.Context, next http.Handler, config config.StripPrefix, name string) (http.Handler, error) {
|
||||
func New(ctx context.Context, next http.Handler, config dynamic.StripPrefix, name string) (http.Handler, error) {
|
||||
middlewares.GetLogger(ctx, name, typeName).Debug("Creating middleware")
|
||||
return &stripPrefix{
|
||||
prefixes: config.Prefixes,
|
||||
|
|
|
@ -6,7 +6,7 @@ import (
|
|||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"github.com/containous/traefik/pkg/config"
|
||||
"github.com/containous/traefik/pkg/config/dynamic"
|
||||
"github.com/containous/traefik/pkg/testhelpers"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
@ -15,7 +15,7 @@ import (
|
|||
func TestStripPrefix(t *testing.T) {
|
||||
testCases := []struct {
|
||||
desc string
|
||||
config config.StripPrefix
|
||||
config dynamic.StripPrefix
|
||||
path string
|
||||
expectedStatusCode int
|
||||
expectedPath string
|
||||
|
@ -24,7 +24,7 @@ func TestStripPrefix(t *testing.T) {
|
|||
}{
|
||||
{
|
||||
desc: "no prefixes configured",
|
||||
config: config.StripPrefix{
|
||||
config: dynamic.StripPrefix{
|
||||
Prefixes: []string{},
|
||||
},
|
||||
path: "/noprefixes",
|
||||
|
@ -32,7 +32,7 @@ func TestStripPrefix(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "wildcard (.*) requests",
|
||||
config: config.StripPrefix{
|
||||
config: dynamic.StripPrefix{
|
||||
Prefixes: []string{"/"},
|
||||
},
|
||||
path: "/",
|
||||
|
@ -42,7 +42,7 @@ func TestStripPrefix(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "prefix and path matching",
|
||||
config: config.StripPrefix{
|
||||
config: dynamic.StripPrefix{
|
||||
Prefixes: []string{"/stat"},
|
||||
},
|
||||
path: "/stat",
|
||||
|
@ -52,7 +52,7 @@ func TestStripPrefix(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "path prefix on exactly matching path",
|
||||
config: config.StripPrefix{
|
||||
config: dynamic.StripPrefix{
|
||||
Prefixes: []string{"/stat/"},
|
||||
},
|
||||
path: "/stat/",
|
||||
|
@ -62,7 +62,7 @@ func TestStripPrefix(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "path prefix on matching longer path",
|
||||
config: config.StripPrefix{
|
||||
config: dynamic.StripPrefix{
|
||||
Prefixes: []string{"/stat/"},
|
||||
},
|
||||
path: "/stat/us",
|
||||
|
@ -72,7 +72,7 @@ func TestStripPrefix(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "path prefix on mismatching path",
|
||||
config: config.StripPrefix{
|
||||
config: dynamic.StripPrefix{
|
||||
Prefixes: []string{"/stat/"},
|
||||
},
|
||||
path: "/status",
|
||||
|
@ -80,7 +80,7 @@ func TestStripPrefix(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "general prefix on matching path",
|
||||
config: config.StripPrefix{
|
||||
config: dynamic.StripPrefix{
|
||||
Prefixes: []string{"/stat"},
|
||||
},
|
||||
path: "/stat/",
|
||||
|
@ -90,7 +90,7 @@ func TestStripPrefix(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "earlier prefix matching",
|
||||
config: config.StripPrefix{
|
||||
config: dynamic.StripPrefix{
|
||||
|
||||
Prefixes: []string{"/stat", "/stat/us"},
|
||||
},
|
||||
|
@ -101,7 +101,7 @@ func TestStripPrefix(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "later prefix matching",
|
||||
config: config.StripPrefix{
|
||||
config: dynamic.StripPrefix{
|
||||
Prefixes: []string{"/mismatch", "/stat"},
|
||||
},
|
||||
path: "/stat",
|
||||
|
@ -111,7 +111,7 @@ func TestStripPrefix(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "prefix matching within slash boundaries",
|
||||
config: config.StripPrefix{
|
||||
config: dynamic.StripPrefix{
|
||||
Prefixes: []string{"/stat"},
|
||||
},
|
||||
path: "/status",
|
||||
|
@ -121,7 +121,7 @@ func TestStripPrefix(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "raw path is also stripped",
|
||||
config: config.StripPrefix{
|
||||
config: dynamic.StripPrefix{
|
||||
Prefixes: []string{"/stat"},
|
||||
},
|
||||
path: "/stat/a%2Fb",
|
||||
|
|
|
@ -6,7 +6,7 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/containous/mux"
|
||||
"github.com/containous/traefik/pkg/config"
|
||||
"github.com/containous/traefik/pkg/config/dynamic"
|
||||
"github.com/containous/traefik/pkg/middlewares"
|
||||
"github.com/containous/traefik/pkg/middlewares/stripprefix"
|
||||
"github.com/containous/traefik/pkg/tracing"
|
||||
|
@ -25,7 +25,7 @@ type stripPrefixRegex struct {
|
|||
}
|
||||
|
||||
// New builds a new StripPrefixRegex middleware.
|
||||
func New(ctx context.Context, next http.Handler, config config.StripPrefixRegex, name string) (http.Handler, error) {
|
||||
func New(ctx context.Context, next http.Handler, config dynamic.StripPrefixRegex, name string) (http.Handler, error) {
|
||||
middlewares.GetLogger(ctx, name, typeName).Debug("Creating middleware")
|
||||
|
||||
stripPrefix := stripPrefixRegex{
|
||||
|
|
|
@ -6,7 +6,7 @@ import (
|
|||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"github.com/containous/traefik/pkg/config"
|
||||
"github.com/containous/traefik/pkg/config/dynamic"
|
||||
"github.com/containous/traefik/pkg/middlewares/stripprefix"
|
||||
"github.com/containous/traefik/pkg/testhelpers"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
@ -14,7 +14,7 @@ import (
|
|||
)
|
||||
|
||||
func TestStripPrefixRegex(t *testing.T) {
|
||||
testPrefixRegex := config.StripPrefixRegex{
|
||||
testPrefixRegex := dynamic.StripPrefixRegex{
|
||||
Regex: []string{"/a/api/", "/b/{regex}/", "/c/{category}/{id:[0-9]+}/"},
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue