middleware.go 1.3 KB

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