Quellcode durchsuchen

Remove unnecessary hardcoded version.

The server configuration already keeps the current version
if the daemon. This patch changes the middleware logic
to use it rather than using the global value.

This removes the dockerversion package dependency from the api.

Signed-off-by: David Calavera <david.calavera@gmail.com>
David Calavera vor 9 Jahren
Ursprung
Commit
accf28a7db
2 geänderte Dateien mit 10 neuen und 3 gelöschten Zeilen
  1. 1 2
      api/server/middleware.go
  2. 9 1
      api/server/server_test.go

+ 1 - 2
api/server/middleware.go

@@ -5,7 +5,6 @@ import (
 	"github.com/docker/docker/api"
 	"github.com/docker/docker/api"
 	"github.com/docker/docker/api/server/httputils"
 	"github.com/docker/docker/api/server/httputils"
 	"github.com/docker/docker/api/server/middleware"
 	"github.com/docker/docker/api/server/middleware"
-	"github.com/docker/docker/dockerversion"
 	"github.com/docker/docker/pkg/authorization"
 	"github.com/docker/docker/pkg/authorization"
 )
 )
 
 
@@ -15,7 +14,7 @@ import (
 func (s *Server) handleWithGlobalMiddlewares(handler httputils.APIFunc) httputils.APIFunc {
 func (s *Server) handleWithGlobalMiddlewares(handler httputils.APIFunc) httputils.APIFunc {
 	next := handler
 	next := handler
 
 
-	handleVersion := middleware.NewVersionMiddleware(dockerversion.Version, api.DefaultVersion, api.MinVersion)
+	handleVersion := middleware.NewVersionMiddleware(s.cfg.Version, api.DefaultVersion, api.MinVersion)
 	next = handleVersion(next)
 	next = handleVersion(next)
 
 
 	if s.cfg.EnableCors {
 	if s.cfg.EnableCors {

+ 9 - 1
api/server/server_test.go

@@ -3,6 +3,7 @@ package server
 import (
 import (
 	"net/http"
 	"net/http"
 	"net/http/httptest"
 	"net/http/httptest"
+	"strings"
 	"testing"
 	"testing"
 
 
 	"github.com/docker/docker/api/server/httputils"
 	"github.com/docker/docker/api/server/httputils"
@@ -11,7 +12,9 @@ import (
 )
 )
 
 
 func TestMiddlewares(t *testing.T) {
 func TestMiddlewares(t *testing.T) {
-	cfg := &Config{}
+	cfg := &Config{
+		Version: "0.1omega2",
+	}
 	srv := &Server{
 	srv := &Server{
 		cfg: cfg,
 		cfg: cfg,
 	}
 	}
@@ -24,6 +27,11 @@ func TestMiddlewares(t *testing.T) {
 		if httputils.VersionFromContext(ctx) == "" {
 		if httputils.VersionFromContext(ctx) == "" {
 			t.Fatalf("Expected version, got empty string")
 			t.Fatalf("Expected version, got empty string")
 		}
 		}
+
+		if sv := w.Header().Get("Server"); !strings.Contains(sv, "Docker/0.1omega2") {
+			t.Fatalf("Expected server version in the header `Docker/0.1omega2`, got %s", sv)
+		}
+
 		return nil
 		return nil
 	}
 	}