github.com/hustcat/docker@v1.3.3-0.20160314103604-901c67a8eeab/api/server/middleware.go (about) 1 package server 2 3 import ( 4 "github.com/Sirupsen/logrus" 5 "github.com/docker/docker/api" 6 "github.com/docker/docker/api/server/httputils" 7 "github.com/docker/docker/api/server/middleware" 8 "github.com/docker/docker/dockerversion" 9 "github.com/docker/docker/pkg/authorization" 10 ) 11 12 // handleWithGlobalMiddlwares wraps the handler function for a request with 13 // the server's global middlewares. The order of the middlewares is backwards, 14 // meaning that the first in the list will be evaluated last. 15 func (s *Server) handleWithGlobalMiddlewares(handler httputils.APIFunc) httputils.APIFunc { 16 next := handler 17 18 handleVersion := middleware.NewVersionMiddleware(dockerversion.Version, api.DefaultVersion, api.MinVersion) 19 next = handleVersion(next) 20 21 if s.cfg.EnableCors { 22 handleCORS := middleware.NewCORSMiddleware(s.cfg.CorsHeaders) 23 next = handleCORS(next) 24 } 25 26 handleUserAgent := middleware.NewUserAgentMiddleware(s.cfg.Version) 27 next = handleUserAgent(next) 28 29 // Only want this on debug level 30 if s.cfg.Logging && logrus.GetLevel() == logrus.DebugLevel { 31 next = middleware.DebugRequestMiddleware(next) 32 } 33 34 if len(s.cfg.AuthorizationPluginNames) > 0 { 35 s.authZPlugins = authorization.NewPlugins(s.cfg.AuthorizationPluginNames) 36 handleAuthorization := middleware.NewAuthorizationMiddleware(s.authZPlugins) 37 next = handleAuthorization(next) 38 } 39 40 return next 41 }