2015-09-15 19:01:49 -04:00
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/Sirupsen/logrus"
|
|
|
|
"github.com/docker/docker/api"
|
2015-09-23 19:42:08 -04:00
|
|
|
"github.com/docker/docker/api/server/httputils"
|
2016-02-24 13:17:43 -05:00
|
|
|
"github.com/docker/docker/api/server/middleware"
|
2015-11-12 06:06:47 -05:00
|
|
|
"github.com/docker/docker/pkg/authorization"
|
2015-09-15 19:01:49 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
// handleWithGlobalMiddlwares wraps the handler function for a request with
|
|
|
|
// the server's global middlewares. The order of the middlewares is backwards,
|
2015-12-13 11:00:39 -05:00
|
|
|
// meaning that the first in the list will be evaluated last.
|
2015-09-23 19:42:08 -04:00
|
|
|
func (s *Server) handleWithGlobalMiddlewares(handler httputils.APIFunc) httputils.APIFunc {
|
2016-02-24 13:17:43 -05:00
|
|
|
next := handler
|
|
|
|
|
2016-03-23 18:30:06 -04:00
|
|
|
handleVersion := middleware.NewVersionMiddleware(s.cfg.Version, api.DefaultVersion, api.MinVersion)
|
2016-02-24 13:17:43 -05:00
|
|
|
next = handleVersion(next)
|
|
|
|
|
|
|
|
if s.cfg.EnableCors {
|
|
|
|
handleCORS := middleware.NewCORSMiddleware(s.cfg.CorsHeaders)
|
|
|
|
next = handleCORS(next)
|
2015-09-15 19:01:49 -04:00
|
|
|
}
|
|
|
|
|
2016-02-24 13:17:43 -05:00
|
|
|
handleUserAgent := middleware.NewUserAgentMiddleware(s.cfg.Version)
|
|
|
|
next = handleUserAgent(next)
|
|
|
|
|
2015-10-22 10:55:23 -04:00
|
|
|
// Only want this on debug level
|
2015-12-01 14:33:33 -05:00
|
|
|
if s.cfg.Logging && logrus.GetLevel() == logrus.DebugLevel {
|
2016-02-24 13:17:43 -05:00
|
|
|
next = middleware.DebugRequestMiddleware(next)
|
2015-10-22 10:55:23 -04:00
|
|
|
}
|
|
|
|
|
2016-01-12 19:38:18 -05:00
|
|
|
if len(s.cfg.AuthorizationPluginNames) > 0 {
|
|
|
|
s.authZPlugins = authorization.NewPlugins(s.cfg.AuthorizationPluginNames)
|
2016-02-24 13:17:43 -05:00
|
|
|
handleAuthorization := middleware.NewAuthorizationMiddleware(s.authZPlugins)
|
|
|
|
next = handleAuthorization(next)
|
2015-11-12 06:06:47 -05:00
|
|
|
}
|
|
|
|
|
2016-02-24 13:17:43 -05:00
|
|
|
return next
|
2015-09-15 19:01:49 -04:00
|
|
|
}
|