1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #13749 from Microsoft/adduseragent

Add GOOS in User-Agent
This commit is contained in:
Arnaud Porterie 2015-06-12 17:19:51 -07:00
commit 422fa7f0a6
5 changed files with 20 additions and 3 deletions

View file

@ -149,7 +149,7 @@ func (cli *DockerCli) hijack(method, path string, setRawTerminal bool, in io.Rea
req.Header.Set(k, v)
}
req.Header.Set("User-Agent", "Docker-Client/"+dockerversion.VERSION)
req.Header.Set("User-Agent", "Docker-Client/"+dockerversion.VERSION+" ("+runtime.GOOS+")")
req.Header.Set("Content-Type", "text/plain")
req.Header.Set("Connection", "Upgrade")
req.Header.Set("Upgrade", "tcp")

View file

@ -64,7 +64,7 @@ func (cli *DockerCli) clientRequest(method, path string, in io.Reader, headers m
req.Header.Set(k, v)
}
req.Header.Set("User-Agent", "Docker-Client/"+dockerversion.VERSION)
req.Header.Set("User-Agent", "Docker-Client/"+dockerversion.VERSION+" ("+runtime.GOOS+")")
req.URL.Host = cli.addr
req.URL.Scheme = cli.scheme

View file

@ -1465,6 +1465,13 @@ func makeHttpHandler(logging bool, localMethod string, localRoute string, handle
if strings.Contains(r.Header.Get("User-Agent"), "Docker-Client/") {
userAgent := strings.Split(r.Header.Get("User-Agent"), "/")
// v1.20 onwards includes the GOOS of the client after the version
// such as Docker/1.7.0 (linux)
if len(userAgent) == 2 && strings.Contains(userAgent[1], " ") {
userAgent[1] = strings.Split(userAgent[1], " ")[0]
}
if len(userAgent) == 2 && !dockerVersion.Equal(version.Version(userAgent[1])) {
logrus.Debugf("Warning: client and server don't have the same version (client: %s, server: %s)", userAgent[1], dockerVersion)
}

View file

@ -35,7 +35,7 @@ func (s *DockerSuite) TestVersionStatusCode(c *check.C) {
req, err := http.NewRequest("GET", "/v999.0/version", nil)
c.Assert(err, check.IsNil)
req.Header.Set("User-Agent", "Docker-Client/999.0")
req.Header.Set("User-Agent", "Docker-Client/999.0 (os)")
res, err := client.Do(req)
c.Assert(res.StatusCode, check.Equals, http.StatusBadRequest)

View file

@ -7,7 +7,9 @@ import (
"os"
"os/exec"
"path/filepath"
"runtime"
"github.com/docker/docker/autogen/dockerversion"
"github.com/docker/docker/pkg/homedir"
"github.com/go-check/check"
)
@ -50,6 +52,14 @@ func (s *DockerSuite) TestConfigHttpHeader(c *check.C) {
cmd := exec.Command(dockerBinary, "-H="+server.URL[7:], "ps")
out, _, _ := runCommandWithOutput(cmd)
if headers["User-Agent"] == nil {
c.Fatalf("Missing User-Agent: %q\nout:%v", headers, out)
}
if headers["User-Agent"][0] != "Docker-Client/"+dockerversion.VERSION+" ("+runtime.GOOS+")" {
c.Fatalf("Badly formatted User-Agent: %q\nout:%v", headers, out)
}
if headers["Myheader"] == nil || headers["Myheader"][0] != "MyValue" {
c.Fatalf("Missing/bad header: %q\nout:%v", headers, out)
}