Use pointer of error pages

This commit is contained in:
Ludovic Fernandez 2017-12-21 11:26:03 +01:00 committed by Traefiker
parent 4a7297d05c
commit 59549d5f39
4 changed files with 20 additions and 18 deletions

View file

@ -19,7 +19,7 @@ type ErrorPagesHandler struct {
}
//NewErrorPagesHandler initializes the utils.ErrorHandler for the custom error pages
func NewErrorPagesHandler(errorPage types.ErrorPage, backendURL string) (*ErrorPagesHandler, error) {
func NewErrorPagesHandler(errorPage *types.ErrorPage, backendURL string) (*ErrorPagesHandler, error) {
fwd, err := forward.New()
if err != nil {
return nil, err

View file

@ -21,7 +21,7 @@ func TestErrorPage(t *testing.T) {
testErrorPage := &types.ErrorPage{Backend: "error", Query: "/test", Status: []string{"500-501", "503-599"}}
testHandler, err := NewErrorPagesHandler(*testErrorPage, ts.URL)
testHandler, err := NewErrorPagesHandler(testErrorPage, ts.URL)
require.NoError(t, err)
assert.Equal(t, testHandler.BackendURL, ts.URL+"/test", "Should be equal")
@ -39,9 +39,11 @@ func TestErrorPage(t *testing.T) {
n.ServeHTTP(recorder, req)
assert.Equal(t, http.StatusOK, recorder.Code, "HTTP statusOK")
assert.Equal(t, http.StatusOK, recorder.Code, "HTTP status")
assert.Contains(t, recorder.Body.String(), "traefik")
// ----
handler500 := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusInternalServerError)
fmt.Fprintln(w, "oops")
@ -86,7 +88,7 @@ func TestErrorPageQuery(t *testing.T) {
testErrorPage := &types.ErrorPage{Backend: "error", Query: "/{status}", Status: []string{"503-503"}}
testHandler, err := NewErrorPagesHandler(*testErrorPage, ts.URL)
testHandler, err := NewErrorPagesHandler(testErrorPage, ts.URL)
require.NoError(t, err)
assert.Equal(t, testHandler.BackendURL, ts.URL+"/{status}", "Should be equal")
@ -125,7 +127,7 @@ func TestErrorPageSingleCode(t *testing.T) {
testErrorPage := &types.ErrorPage{Backend: "error", Query: "/{status}", Status: []string{"503"}}
testHandler, err := NewErrorPagesHandler(*testErrorPage, ts.URL)
testHandler, err := NewErrorPagesHandler(testErrorPage, ts.URL)
require.NoError(t, err)
assert.Equal(t, testHandler.BackendURL, ts.URL+"/{status}", "Should be equal")

View file

@ -213,7 +213,7 @@ func TestDockerBuildConfiguration(t *testing.T) {
Rule: "Host:test1.docker.localhost",
},
},
Errors: map[string]types.ErrorPage{
Errors: map[string]*types.ErrorPage{
"foo": {
Status: []string{"404"},
Query: "foo_query",

View file

@ -142,18 +142,18 @@ func (h Headers) HasSecureHeadersDefined() bool {
// Frontend holds frontend configuration.
type Frontend struct {
EntryPoints []string `json:"entryPoints,omitempty"`
Backend string `json:"backend,omitempty"`
Routes map[string]Route `json:"routes,omitempty"`
PassHostHeader bool `json:"passHostHeader,omitempty"`
PassTLSCert bool `json:"passTLSCert,omitempty"`
Priority int `json:"priority"`
BasicAuth []string `json:"basicAuth"`
WhitelistSourceRange []string `json:"whitelistSourceRange,omitempty"`
Headers Headers `json:"headers,omitempty"`
Errors map[string]ErrorPage `json:"errors,omitempty"`
RateLimit *RateLimit `json:"ratelimit,omitempty"`
Redirect *Redirect `json:"redirect,omitempty"`
EntryPoints []string `json:"entryPoints,omitempty"`
Backend string `json:"backend,omitempty"`
Routes map[string]Route `json:"routes,omitempty"`
PassHostHeader bool `json:"passHostHeader,omitempty"`
PassTLSCert bool `json:"passTLSCert,omitempty"`
Priority int `json:"priority"`
BasicAuth []string `json:"basicAuth"`
WhitelistSourceRange []string `json:"whitelistSourceRange,omitempty"`
Headers Headers `json:"headers,omitempty"`
Errors map[string]*ErrorPage `json:"errors,omitempty"`
RateLimit *RateLimit `json:"ratelimit,omitempty"`
Redirect *Redirect `json:"redirect,omitempty"`
}
// Redirect configures a redirection of an entry point to another, or to an URL