mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-23 22:27:38 -05:00
Remove path scoping for middleware slice
It was implemented for almost a year but we'll probably never use it, especially since we'll match more than the path in the future.
This commit is contained in:
parent
f25ae8230f
commit
1ef7f3c4b1
5 changed files with 12 additions and 24 deletions
|
@ -11,7 +11,6 @@ import (
|
|||
"github.com/mholt/caddy/caddy/https"
|
||||
"github.com/mholt/caddy/caddy/parse"
|
||||
"github.com/mholt/caddy/caddy/setup"
|
||||
"github.com/mholt/caddy/middleware"
|
||||
"github.com/mholt/caddy/server"
|
||||
)
|
||||
|
||||
|
@ -55,7 +54,6 @@ func loadConfigsUpToIncludingTLS(filename string, input io.Reader) ([]server.Con
|
|||
Port: addr.Port,
|
||||
Scheme: addr.Scheme,
|
||||
Root: Root,
|
||||
Middleware: make(map[string][]middleware.Middleware),
|
||||
ConfigFile: filename,
|
||||
AppName: AppName,
|
||||
AppVersion: AppVersion,
|
||||
|
@ -89,8 +87,7 @@ func loadConfigsUpToIncludingTLS(filename string, input io.Reader) ([]server.Con
|
|||
return nil, nil, lastDirectiveIndex, err
|
||||
}
|
||||
if midware != nil {
|
||||
// TODO: For now, we only support the default path scope /
|
||||
config.Middleware["/"] = append(config.Middleware["/"], midware)
|
||||
config.Middleware = append(config.Middleware, midware)
|
||||
}
|
||||
storages[dir.name] = controller.ServerBlockStorage // persist for this server block
|
||||
}
|
||||
|
@ -171,8 +168,7 @@ func loadConfigs(filename string, input io.Reader) ([]server.Config, error) {
|
|||
return nil, err
|
||||
}
|
||||
if midware != nil {
|
||||
// TODO: For now, we only support the default path scope /
|
||||
configs[configIndex].Middleware["/"] = append(configs[configIndex].Middleware["/"], midware)
|
||||
configs[configIndex].Middleware = append(configs[configIndex].Middleware, midware)
|
||||
}
|
||||
storages[dir.name] = controller.ServerBlockStorage // persist for this server block
|
||||
}
|
||||
|
|
|
@ -335,9 +335,7 @@ func redirPlaintextHost(cfg server.Config) server.Config {
|
|||
Host: cfg.Host,
|
||||
BindHost: cfg.BindHost,
|
||||
Port: "80",
|
||||
Middleware: map[string][]middleware.Middleware{
|
||||
"/": {redirMidware},
|
||||
},
|
||||
Middleware: []middleware.Middleware{redirMidware},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -87,11 +87,11 @@ func TestRedirPlaintextHost(t *testing.T) {
|
|||
}
|
||||
|
||||
// Make sure redirect handler is set up properly
|
||||
if cfg.Middleware == nil || len(cfg.Middleware["/"]) != 1 {
|
||||
if cfg.Middleware == nil || len(cfg.Middleware) != 1 {
|
||||
t.Fatalf("Redir config middleware not set up properly; got: %#v", cfg.Middleware)
|
||||
}
|
||||
|
||||
handler, ok := cfg.Middleware["/"][0](nil).(redirect.Redirect)
|
||||
handler, ok := cfg.Middleware[0](nil).(redirect.Redirect)
|
||||
if !ok {
|
||||
t.Fatalf("Expected a redirect.Redirect middleware, but got: %#v", handler)
|
||||
}
|
||||
|
@ -116,7 +116,7 @@ func TestRedirPlaintextHost(t *testing.T) {
|
|||
// browsers can infer a default port from scheme, so make sure the port
|
||||
// doesn't get added in explicitly for default ports like 443 for https.
|
||||
cfg = redirPlaintextHost(server.Config{Host: "example.com", Port: "443"})
|
||||
handler, ok = cfg.Middleware["/"][0](nil).(redirect.Redirect)
|
||||
handler, ok = cfg.Middleware[0](nil).(redirect.Redirect)
|
||||
if actual, expected := handler.Rules[0].To, "https://{host}{uri}"; actual != expected {
|
||||
t.Errorf("(Default Port) Expected redirect rule to be to URL '%s' but is actually to '%s'", expected, actual)
|
||||
}
|
||||
|
|
|
@ -26,8 +26,8 @@ type Config struct {
|
|||
// HTTPS configuration
|
||||
TLS TLSConfig
|
||||
|
||||
// Middleware stack; map of path scope to middleware -- TODO: Support path scope?
|
||||
Middleware map[string][]middleware.Middleware
|
||||
// Middleware stack
|
||||
Middleware []middleware.Middleware
|
||||
|
||||
// Startup is a list of functions (or methods) to execute at
|
||||
// server startup and restart; these are executed before any
|
||||
|
|
|
@ -21,13 +21,7 @@ type virtualHost struct {
|
|||
// ListenAndServe begins.
|
||||
func (vh *virtualHost) buildStack() error {
|
||||
vh.fileServer = middleware.FileServer(http.Dir(vh.config.Root), []string{vh.config.ConfigFile})
|
||||
|
||||
// TODO: We only compile middleware for the "/" scope.
|
||||
// Partial support for multiple location contexts already
|
||||
// exists at the parser and config levels, but until full
|
||||
// support is implemented, this is all we do right here.
|
||||
vh.compile(vh.config.Middleware["/"])
|
||||
|
||||
vh.compile(vh.config.Middleware)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue