middleware.go 1.3 KB

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