From 64981b9f095459ae65954ca80a86c8f4a735ef24 Mon Sep 17 00:00:00 2001 From: Tonis Tiigi Date: Thu, 22 Dec 2016 13:51:47 -0800 Subject: [PATCH] Move UAStringKey to dockerversion pkg Removes grpc dependency from client Signed-off-by: Tonis Tiigi --- api/server/httputils/httputils.go | 3 --- api/server/server.go | 3 ++- dockerversion/useragent.go | 8 +++++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/api/server/httputils/httputils.go b/api/server/httputils/httputils.go index d37ee5cafe..2c2e8452f9 100644 --- a/api/server/httputils/httputils.go +++ b/api/server/httputils/httputils.go @@ -14,9 +14,6 @@ import ( // APIVersionKey is the client's requested 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. // 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 diff --git a/api/server/server.go b/api/server/server.go index d988b8e17f..d8b716e100 100644 --- a/api/server/server.go +++ b/api/server/server.go @@ -12,6 +12,7 @@ import ( "github.com/docker/docker/api/server/httputils" "github.com/docker/docker/api/server/middleware" "github.com/docker/docker/api/server/router" + "github.com/docker/docker/dockerversion" "github.com/gorilla/mux" "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 // immediate function being called should still be passed // 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) vars := mux.Vars(r) diff --git a/dockerversion/useragent.go b/dockerversion/useragent.go index d2a891c4d6..53632cbc35 100644 --- a/dockerversion/useragent.go +++ b/dockerversion/useragent.go @@ -4,12 +4,14 @@ import ( "fmt" "runtime" - "github.com/docker/docker/api/server/httputils" "github.com/docker/docker/pkg/parsers/kernel" "github.com/docker/docker/pkg/useragent" "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. // In accordance with RFC 7231 (5.5.3) is of the form: // [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 { var upstreamUA string if ctx != nil { - var ki interface{} = ctx.Value(httputils.UAStringKey) + var ki interface{} = ctx.Value(UAStringKey) if ki != nil { - upstreamUA = ctx.Value(httputils.UAStringKey).(string) + upstreamUA = ctx.Value(UAStringKey).(string) } } return upstreamUA