Make version check return 400 instead of 404
| ... | ... |
@@ -1426,7 +1426,7 @@ func makeHttpHandler(logging bool, localMethod string, localRoute string, handle |
| 1426 | 1426 |
} |
| 1427 | 1427 |
|
| 1428 | 1428 |
if version.GreaterThan(api.APIVERSION) {
|
| 1429 |
- 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)
|
|
| 1429 |
+ 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)
|
|
| 1430 | 1430 |
return |
| 1431 | 1431 |
} |
| 1432 | 1432 |
|
| ... | ... |
@@ -46,6 +46,11 @@ You can still call an old version of the API using |
| 46 | 46 |
|
| 47 | 47 |
### What's new |
| 48 | 48 |
|
| 49 |
+**New!** |
|
| 50 |
+When the daemon detects a version mismatch with the client, usually when |
|
| 51 |
+the client is newer than the daemon, an HTTP 400 is now returned instead |
|
| 52 |
+of a 404. |
|
| 53 |
+ |
|
| 49 | 54 |
`GET /containers/(id)/stats` |
| 50 | 55 |
|
| 51 | 56 |
**New!** |
| ... | ... |
@@ -13,6 +13,8 @@ page_keywords: API, Docker, rcli, REST, documentation |
| 13 | 13 |
- The API tends to be REST, but for some complex commands, like `attach` |
| 14 | 14 |
or `pull`, the HTTP connection is hijacked to transport `STDOUT`, |
| 15 | 15 |
`STDIN` and `STDERR`. |
| 16 |
+ - When the client API version is newer than the daemon's an HTTP |
|
| 17 |
+ `400 Bad Request` error message is returned. |
|
| 16 | 18 |
|
| 17 | 19 |
# 2. Endpoints |
| 18 | 20 |
|
| ... | ... |
@@ -2,6 +2,8 @@ package main |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 | 4 |
"net/http" |
| 5 |
+ "net/http/httputil" |
|
| 6 |
+ "time" |
|
| 5 | 7 |
|
| 6 | 8 |
"github.com/go-check/check" |
| 7 | 9 |
) |
| ... | ... |
@@ -23,3 +25,18 @@ func (s *DockerSuite) TestApiGetEnabledCors(c *check.C) {
|
| 23 | 23 |
//c.Assert(res.Header.Get("Access-Control-Allow-Origin"), check.Equals, "*")
|
| 24 | 24 |
//c.Assert(res.Header.Get("Access-Control-Allow-Headers"), check.Equals, "Origin, X-Requested-With, Content-Type, Accept, X-Registry-Auth")
|
| 25 | 25 |
} |
| 26 |
+ |
|
| 27 |
+func (s *DockerSuite) TestVersionStatusCode(c *check.C) {
|
|
| 28 |
+ conn, err := sockConn(time.Duration(10 * time.Second)) |
|
| 29 |
+ c.Assert(err, check.IsNil) |
|
| 30 |
+ |
|
| 31 |
+ client := httputil.NewClientConn(conn, nil) |
|
| 32 |
+ defer client.Close() |
|
| 33 |
+ |
|
| 34 |
+ req, err := http.NewRequest("GET", "/v999.0/version", nil)
|
|
| 35 |
+ c.Assert(err, check.IsNil) |
|
| 36 |
+ req.Header.Set("User-Agent", "Docker-Client/999.0")
|
|
| 37 |
+ |
|
| 38 |
+ res, err := client.Do(req) |
|
| 39 |
+ c.Assert(res.StatusCode, check.Equals, http.StatusBadRequest) |
|
| 40 |
+} |