Migrate Compress from bool to struct

This commit is contained in:
Jean-Baptiste Doumenjou 2018-08-02 17:14:03 +02:00 committed by Traefiker Bot
parent 43d22d7a2f
commit c159e316be
6 changed files with 19 additions and 12 deletions

View file

@ -81,7 +81,7 @@ func TestDo_globalConfiguration(t *testing.T) {
}, },
}, },
WhitelistSourceRange: []string{"foo WhitelistSourceRange 1", "foo WhitelistSourceRange 2", "foo WhitelistSourceRange 3"}, WhitelistSourceRange: []string{"foo WhitelistSourceRange 1", "foo WhitelistSourceRange 2", "foo WhitelistSourceRange 3"},
Compress: true, Compress: &configuration.Compress{},
ProxyProtocol: &configuration.ProxyProtocol{ ProxyProtocol: &configuration.ProxyProtocol{
TrustedIPs: []string{"127.0.0.1/32", "192.168.0.1"}, TrustedIPs: []string{"127.0.0.1/32", "192.168.0.1"},
}, },
@ -126,7 +126,7 @@ func TestDo_globalConfiguration(t *testing.T) {
}, },
}, },
WhitelistSourceRange: []string{"fii WhitelistSourceRange 1", "fii WhitelistSourceRange 2", "fii WhitelistSourceRange 3"}, WhitelistSourceRange: []string{"fii WhitelistSourceRange 1", "fii WhitelistSourceRange 2", "fii WhitelistSourceRange 3"},
Compress: true, Compress: &configuration.Compress{},
ProxyProtocol: &configuration.ProxyProtocol{ ProxyProtocol: &configuration.ProxyProtocol{
TrustedIPs: []string{"127.0.0.1/32", "192.168.0.1"}, TrustedIPs: []string{"127.0.0.1/32", "192.168.0.1"},
}, },

View file

@ -17,11 +17,15 @@ type EntryPoint struct {
Auth *types.Auth `export:"true"` Auth *types.Auth `export:"true"`
WhitelistSourceRange []string // Deprecated WhitelistSourceRange []string // Deprecated
WhiteList *types.WhiteList `export:"true"` WhiteList *types.WhiteList `export:"true"`
Compress bool `export:"true"` Compress *Compress `export:"true"`
ProxyProtocol *ProxyProtocol `export:"true"` ProxyProtocol *ProxyProtocol `export:"true"`
ForwardedHeaders *ForwardedHeaders `export:"true"` ForwardedHeaders *ForwardedHeaders `export:"true"`
} }
// Compress contains compress configuration
type Compress struct {
}
// ProxyProtocol contains Proxy-Protocol configuration // ProxyProtocol contains Proxy-Protocol configuration
type ProxyProtocol struct { type ProxyProtocol struct {
Insecure bool `export:"true"` Insecure bool `export:"true"`
@ -69,7 +73,10 @@ func (ep *EntryPoints) Set(value string) error {
whiteListSourceRange = strings.Split(result["whitelistsourcerange"], ",") whiteListSourceRange = strings.Split(result["whitelistsourcerange"], ",")
} }
compress := toBool(result, "compress") var compress *Compress
if len(result["compress"]) > 0 {
compress = &Compress{}
}
configTLS, err := makeEntryPointTLS(result) configTLS, err := makeEntryPointTLS(result)
if err != nil { if err != nil {

View file

@ -278,7 +278,7 @@ func TestEntryPoints_Set(t *testing.T) {
}, },
UseXForwardedFor: true, UseXForwardedFor: true,
}, },
Compress: true, Compress: &Compress{},
ProxyProtocol: &ProxyProtocol{ ProxyProtocol: &ProxyProtocol{
Insecure: false, Insecure: false,
TrustedIPs: []string{"192.168.0.1"}, TrustedIPs: []string{"192.168.0.1"},
@ -380,7 +380,7 @@ func TestEntryPoints_Set(t *testing.T) {
"152.89.1.33/32", "152.89.1.33/32",
"afed:be44::/16", "afed:be44::/16",
}, },
Compress: true, Compress: &Compress{},
ProxyProtocol: &ProxyProtocol{ ProxyProtocol: &ProxyProtocol{
Insecure: false, Insecure: false,
TrustedIPs: []string{"192.168.0.1"}, TrustedIPs: []string{"192.168.0.1"},
@ -462,7 +462,7 @@ func TestEntryPoints_Set(t *testing.T) {
expression: "Name:foo Compress:on", expression: "Name:foo Compress:on",
expectedEntryPointName: "foo", expectedEntryPointName: "foo",
expectedEntryPoint: &EntryPoint{ expectedEntryPoint: &EntryPoint{
Compress: true, Compress: &Compress{},
ForwardedHeaders: &ForwardedHeaders{Insecure: true}, ForwardedHeaders: &ForwardedHeaders{Insecure: true},
}, },
}, },
@ -471,7 +471,7 @@ func TestEntryPoints_Set(t *testing.T) {
expression: "Name:foo Compress:true", expression: "Name:foo Compress:true",
expectedEntryPointName: "foo", expectedEntryPointName: "foo",
expectedEntryPoint: &EntryPoint{ expectedEntryPoint: &EntryPoint{
Compress: true, Compress: &Compress{},
ForwardedHeaders: &ForwardedHeaders{Insecure: true}, ForwardedHeaders: &ForwardedHeaders{Insecure: true},
}, },
}, },

View file

@ -13,7 +13,7 @@ defaultEntryPoints = ["http", "https"]
[entryPoints] [entryPoints]
[entryPoints.http] [entryPoints.http]
address = ":80" address = ":80"
compress = true [entryPoints.http.compress]
[entryPoints.http.whitelist] [entryPoints.http.whitelist]
sourceRange = ["10.42.0.0/16", "152.89.1.33/32", "afed:be44::/16"] sourceRange = ["10.42.0.0/16", "152.89.1.33/32", "afed:be44::/16"]
@ -453,7 +453,7 @@ To enable compression support using gzip format.
[entryPoints] [entryPoints]
[entryPoints.http] [entryPoints.http]
address = ":80" address = ":80"
compress = true [entryPoints.http.compress]
``` ```
Responses are compressed when: Responses are compressed when:

View file

@ -9,7 +9,7 @@ import (
"github.com/containous/traefik/log" "github.com/containous/traefik/log"
) )
// Compress is a middleware that allows redirection // Compress is a middleware that allows to compress the response
type Compress struct{} type Compress struct{}
// ServeHTTP is a function used by Negroni // ServeHTTP is a function used by Negroni

View file

@ -158,7 +158,7 @@ func (s *Server) buildServerEntryPointMiddlewares(serverEntryPointName string, s
serverMiddlewares = append(serverMiddlewares, s.wrapNegroniHandlerWithAccessLog(authMiddleware, fmt.Sprintf("Auth for entrypoint %s", serverEntryPointName))) serverMiddlewares = append(serverMiddlewares, s.wrapNegroniHandlerWithAccessLog(authMiddleware, fmt.Sprintf("Auth for entrypoint %s", serverEntryPointName)))
} }
if s.entryPoints[serverEntryPointName].Configuration.Compress { if s.entryPoints[serverEntryPointName].Configuration.Compress != nil {
serverMiddlewares = append(serverMiddlewares, &middlewares.Compress{}) serverMiddlewares = append(serverMiddlewares, &middlewares.Compress{})
} }