Browse code

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 authored on 2016/03/24 07:30:06
Showing 2 changed files
... ...
@@ -5,7 +5,6 @@ import (
5 5
 	"github.com/docker/docker/api"
6 6
 	"github.com/docker/docker/api/server/httputils"
7 7
 	"github.com/docker/docker/api/server/middleware"
8
-	"github.com/docker/docker/dockerversion"
9 8
 	"github.com/docker/docker/pkg/authorization"
10 9
 )
11 10
 
... ...
@@ -15,7 +14,7 @@ import (
15 15
 func (s *Server) handleWithGlobalMiddlewares(handler httputils.APIFunc) httputils.APIFunc {
16 16
 	next := handler
17 17
 
18
-	handleVersion := middleware.NewVersionMiddleware(dockerversion.Version, api.DefaultVersion, api.MinVersion)
18
+	handleVersion := middleware.NewVersionMiddleware(s.cfg.Version, api.DefaultVersion, api.MinVersion)
19 19
 	next = handleVersion(next)
20 20
 
21 21
 	if s.cfg.EnableCors {
... ...
@@ -3,6 +3,7 @@ package server
3 3
 import (
4 4
 	"net/http"
5 5
 	"net/http/httptest"
6
+	"strings"
6 7
 	"testing"
7 8
 
8 9
 	"github.com/docker/docker/api/server/httputils"
... ...
@@ -11,7 +12,9 @@ import (
11 11
 )
12 12
 
13 13
 func TestMiddlewares(t *testing.T) {
14
-	cfg := &Config{}
14
+	cfg := &Config{
15
+		Version: "0.1omega2",
16
+	}
15 17
 	srv := &Server{
16 18
 		cfg: cfg,
17 19
 	}
... ...
@@ -24,6 +27,11 @@ func TestMiddlewares(t *testing.T) {
24 24
 		if httputils.VersionFromContext(ctx) == "" {
25 25
 			t.Fatalf("Expected version, got empty string")
26 26
 		}
27
+
28
+		if sv := w.Header().Get("Server"); !strings.Contains(sv, "Docker/0.1omega2") {
29
+			t.Fatalf("Expected server version in the header `Docker/0.1omega2`, got %s", sv)
30
+		}
31
+
27 32
 		return nil
28 33
 	}
29 34