Selaa lähdekoodia

Move UAStringKey to dockerversion pkg

Removes grpc dependency from client

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
Tonis Tiigi 8 vuotta sitten
vanhempi
commit
64981b9f09
3 muutettua tiedostoa jossa 7 lisäystä ja 7 poistoa
  1. 0 3
      api/server/httputils/httputils.go
  2. 2 1
      api/server/server.go
  3. 5 3
      dockerversion/useragent.go

+ 0 - 3
api/server/httputils/httputils.go

@@ -14,9 +14,6 @@ import (
 // APIVersionKey is the client's requested API version.
 // APIVersionKey is the client's requested API version.
 const APIVersionKey = "api-version"
 const APIVersionKey = "api-version"
 
 
-// UAStringKey is used as key type for user-agent string in net/context struct
-const UAStringKey = "upstream-user-agent"
-
 // APIFunc is an adapter to allow the use of ordinary functions as Docker API endpoints.
 // APIFunc is an adapter to allow the use of ordinary functions as Docker API endpoints.
 // Any function that has the appropriate signature can be registered as an API endpoint (e.g. getVersion).
 // Any function that has the appropriate signature can be registered as an API endpoint (e.g. getVersion).
 type APIFunc func(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error
 type APIFunc func(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error

+ 2 - 1
api/server/server.go

@@ -12,6 +12,7 @@ import (
 	"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/api/server/router"
 	"github.com/docker/docker/api/server/router"
+	"github.com/docker/docker/dockerversion"
 	"github.com/gorilla/mux"
 	"github.com/gorilla/mux"
 	"golang.org/x/net/context"
 	"golang.org/x/net/context"
 )
 )
@@ -128,7 +129,7 @@ func (s *Server) makeHTTPHandler(handler httputils.APIFunc) http.HandlerFunc {
 		// apply to all requests. Data that is specific to the
 		// apply to all requests. Data that is specific to the
 		// immediate function being called should still be passed
 		// immediate function being called should still be passed
 		// as 'args' on the function call.
 		// as 'args' on the function call.
-		ctx := context.WithValue(context.Background(), httputils.UAStringKey, r.Header.Get("User-Agent"))
+		ctx := context.WithValue(context.Background(), dockerversion.UAStringKey, r.Header.Get("User-Agent"))
 		handlerFunc := s.handlerWithGlobalMiddlewares(handler)
 		handlerFunc := s.handlerWithGlobalMiddlewares(handler)
 
 
 		vars := mux.Vars(r)
 		vars := mux.Vars(r)

+ 5 - 3
dockerversion/useragent.go

@@ -4,12 +4,14 @@ import (
 	"fmt"
 	"fmt"
 	"runtime"
 	"runtime"
 
 
-	"github.com/docker/docker/api/server/httputils"
 	"github.com/docker/docker/pkg/parsers/kernel"
 	"github.com/docker/docker/pkg/parsers/kernel"
 	"github.com/docker/docker/pkg/useragent"
 	"github.com/docker/docker/pkg/useragent"
 	"golang.org/x/net/context"
 	"golang.org/x/net/context"
 )
 )
 
 
+// UAStringKey is used as key type for user-agent string in net/context struct
+const UAStringKey = "upstream-user-agent"
+
 // DockerUserAgent is the User-Agent the Docker client uses to identify itself.
 // DockerUserAgent is the User-Agent the Docker client uses to identify itself.
 // In accordance with RFC 7231 (5.5.3) is of the form:
 // In accordance with RFC 7231 (5.5.3) is of the form:
 //    [docker client's UA] UpstreamClient([upstream client's UA])
 //    [docker client's UA] UpstreamClient([upstream client's UA])
@@ -37,9 +39,9 @@ func DockerUserAgent(ctx context.Context) string {
 func getUserAgentFromContext(ctx context.Context) string {
 func getUserAgentFromContext(ctx context.Context) string {
 	var upstreamUA string
 	var upstreamUA string
 	if ctx != nil {
 	if ctx != nil {
-		var ki interface{} = ctx.Value(httputils.UAStringKey)
+		var ki interface{} = ctx.Value(UAStringKey)
 		if ki != nil {
 		if ki != nil {
-			upstreamUA = ctx.Value(httputils.UAStringKey).(string)
+			upstreamUA = ctx.Value(UAStringKey).(string)
 		}
 		}
 	}
 	}
 	return upstreamUA
 	return upstreamUA