瀏覽代碼

Merge pull request #13324 from duglin/BadRCOnVersion

Make version check return 400 instead of 404
Alexander Morozov 10 年之前
父節點
當前提交
53a795378d

+ 1 - 1
api/server/server.go

@@ -1426,7 +1426,7 @@ func makeHttpHandler(logging bool, localMethod string, localRoute string, handle
 		}
 
 		if version.GreaterThan(api.APIVERSION) {
-			http.Error(w, fmt.Errorf("client and server don't have same version (client API version: %s, server API version: %s)", version, api.APIVERSION).Error(), http.StatusNotFound)
+			http.Error(w, fmt.Errorf("client and server don't have same version (client API version: %s, server API version: %s)", version, api.APIVERSION).Error(), http.StatusBadRequest)
 			return
 		}
 

+ 5 - 0
docs/sources/reference/api/docker_remote_api.md

@@ -46,6 +46,11 @@ You can still call an old version of the API using
 
 ### What's new
 
+**New!**
+When the daemon detects a version mismatch with the client, usually when
+the client is newer than the daemon, an HTTP 400 is now returned instead
+of a 404.
+
 `GET /containers/(id)/stats`
 
 **New!**

+ 2 - 0
docs/sources/reference/api/docker_remote_api_v1.19.md

@@ -13,6 +13,8 @@ page_keywords: API, Docker, rcli, REST, documentation
  - The API tends to be REST, but for some complex commands, like `attach`
    or `pull`, the HTTP connection is hijacked to transport `STDOUT`,
    `STDIN` and `STDERR`.
+ - When the client API version is newer than the daemon's an HTTP
+   `400 Bad Request` error message is returned.
 
 # 2. Endpoints
 

+ 17 - 0
integration-cli/docker_api_test.go

@@ -2,6 +2,8 @@ package main
 
 import (
 	"net/http"
+	"net/http/httputil"
+	"time"
 
 	"github.com/go-check/check"
 )
@@ -23,3 +25,18 @@ func (s *DockerSuite) TestApiGetEnabledCors(c *check.C) {
 	//c.Assert(res.Header.Get("Access-Control-Allow-Origin"), check.Equals, "*")
 	//c.Assert(res.Header.Get("Access-Control-Allow-Headers"), check.Equals, "Origin, X-Requested-With, Content-Type, Accept, X-Registry-Auth")
 }
+
+func (s *DockerSuite) TestVersionStatusCode(c *check.C) {
+	conn, err := sockConn(time.Duration(10 * time.Second))
+	c.Assert(err, check.IsNil)
+
+	client := httputil.NewClientConn(conn, nil)
+	defer client.Close()
+
+	req, err := http.NewRequest("GET", "/v999.0/version", nil)
+	c.Assert(err, check.IsNil)
+	req.Header.Set("User-Agent", "Docker-Client/999.0")
+
+	res, err := client.Do(req)
+	c.Assert(res.StatusCode, check.Equals, http.StatusBadRequest)
+}