Go automatically canonicalises HTTP headers, meaning the string `API-Version` passed as a header has always been returned as `Api-Version`. Similarly, `OSType` is returned as `Ostype`.
This commit updates the documentation to reflect this behaviour and modifies the codebase to ensure that input strings are aligned with their canonical output values.
Signed-off-by: maggie44 <64841595+maggie44@users.noreply.github.com>
| ... | ... |
@@ -67,8 +67,8 @@ func (e versionUnsupportedError) InvalidParameter() {}
|
| 67 | 67 |
func (v VersionMiddleware) WrapHandler(handler func(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error) func(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
| 68 | 68 |
return func(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
| 69 | 69 |
w.Header().Set("Server", fmt.Sprintf("Docker/%s (%s)", v.serverVersion, runtime.GOOS))
|
| 70 |
- w.Header().Set("API-Version", v.defaultAPIVersion)
|
|
| 71 |
- w.Header().Set("OSType", runtime.GOOS)
|
|
| 70 |
+ w.Header().Set("Api-Version", v.defaultAPIVersion)
|
|
| 71 |
+ w.Header().Set("Ostype", runtime.GOOS)
|
|
| 72 | 72 |
|
| 73 | 73 |
apiVersion := vars["version"] |
| 74 | 74 |
if apiVersion == "" {
|
| ... | ... |
@@ -140,6 +140,6 @@ func TestVersionMiddlewareWithErrorsReturnsHeaders(t *testing.T) {
|
| 140 | 140 |
hdr := resp.Result().Header |
| 141 | 141 |
assert.Check(t, is.Contains(hdr.Get("Server"), "Docker/1.2.3"))
|
| 142 | 142 |
assert.Check(t, is.Contains(hdr.Get("Server"), runtime.GOOS))
|
| 143 |
- assert.Check(t, is.Equal(hdr.Get("API-Version"), api.DefaultVersion))
|
|
| 144 |
- assert.Check(t, is.Equal(hdr.Get("OSType"), runtime.GOOS))
|
|
| 143 |
+ assert.Check(t, is.Equal(hdr.Get("Api-Version"), api.DefaultVersion))
|
|
| 144 |
+ assert.Check(t, is.Equal(hdr.Get("Ostype"), runtime.GOOS))
|
|
| 145 | 145 |
} |
| ... | ... |
@@ -9626,7 +9626,7 @@ paths: |
| 9626 | 9626 |
type: "string" |
| 9627 | 9627 |
example: "OK" |
| 9628 | 9628 |
headers: |
| 9629 |
- API-Version: |
|
| 9629 |
+ Api-Version: |
|
| 9630 | 9630 |
type: "string" |
| 9631 | 9631 |
description: "Max API Version the server supports" |
| 9632 | 9632 |
Builder-Version: |
| ... | ... |
@@ -9682,7 +9682,7 @@ paths: |
| 9682 | 9682 |
type: "string" |
| 9683 | 9683 |
example: "(empty)" |
| 9684 | 9684 |
headers: |
| 9685 |
- API-Version: |
|
| 9685 |
+ Api-Version: |
|
| 9686 | 9686 |
type: "string" |
| 9687 | 9687 |
description: "Max API Version the server supports" |
| 9688 | 9688 |
Builder-Version: |
| ... | ... |
@@ -369,7 +369,7 @@ func TestNegotiateAPIVersionAutomatic(t *testing.T) {
|
| 369 | 369 |
var pingVersion string |
| 370 | 370 |
httpClient := newMockClient(func(req *http.Request) (*http.Response, error) {
|
| 371 | 371 |
resp := &http.Response{StatusCode: http.StatusOK, Header: http.Header{}}
|
| 372 |
- resp.Header.Set("API-Version", pingVersion)
|
|
| 372 |
+ resp.Header.Set("Api-Version", pingVersion)
|
|
| 373 | 373 |
resp.Body = io.NopCloser(strings.NewReader("OK"))
|
| 374 | 374 |
return resp, nil |
| 375 | 375 |
}) |
| ... | ... |
@@ -56,8 +56,8 @@ func parsePingResponse(cli *Client, resp serverResponse) (types.Ping, error) {
|
| 56 | 56 |
err := cli.checkResponseErr(resp) |
| 57 | 57 |
return ping, errdefs.FromStatusCode(err, resp.statusCode) |
| 58 | 58 |
} |
| 59 |
- ping.APIVersion = resp.header.Get("API-Version")
|
|
| 60 |
- ping.OSType = resp.header.Get("OSType")
|
|
| 59 |
+ ping.APIVersion = resp.header.Get("Api-Version")
|
|
| 60 |
+ ping.OSType = resp.header.Get("Ostype")
|
|
| 61 | 61 |
if resp.header.Get("Docker-Experimental") == "true" {
|
| 62 | 62 |
ping.Experimental = true |
| 63 | 63 |
} |
| ... | ... |
@@ -24,7 +24,7 @@ func TestPingFail(t *testing.T) {
|
| 24 | 24 |
resp := &http.Response{StatusCode: http.StatusInternalServerError}
|
| 25 | 25 |
if withHeader {
|
| 26 | 26 |
resp.Header = http.Header{}
|
| 27 |
- resp.Header.Set("API-Version", "awesome")
|
|
| 27 |
+ resp.Header.Set("Api-Version", "awesome")
|
|
| 28 | 28 |
resp.Header.Set("Docker-Experimental", "true")
|
| 29 | 29 |
resp.Header.Set("Swarm", "inactive")
|
| 30 | 30 |
} |
| ... | ... |
@@ -72,7 +72,7 @@ func TestPingSuccess(t *testing.T) {
|
| 72 | 72 |
client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
| 73 | 73 |
resp := &http.Response{StatusCode: http.StatusOK}
|
| 74 | 74 |
resp.Header = http.Header{}
|
| 75 |
- resp.Header.Set("API-Version", "awesome")
|
|
| 75 |
+ resp.Header.Set("Api-Version", "awesome")
|
|
| 76 | 76 |
resp.Header.Set("Docker-Experimental", "true")
|
| 77 | 77 |
resp.Header.Set("Swarm", "active/manager")
|
| 78 | 78 |
resp.Body = io.NopCloser(strings.NewReader("OK"))
|
| ... | ... |
@@ -121,7 +121,7 @@ func TestPingHeadFallback(t *testing.T) {
|
| 121 | 121 |
resp.StatusCode = tc.status |
| 122 | 122 |
} |
| 123 | 123 |
resp.Header = http.Header{}
|
| 124 |
- resp.Header.Add("API-Version", strings.Join(reqs, ", "))
|
|
| 124 |
+ resp.Header.Add("Api-Version", strings.Join(reqs, ", "))
|
|
| 125 | 125 |
return resp, nil |
| 126 | 126 |
}), |
| 127 | 127 |
} |
| ... | ... |
@@ -38,7 +38,7 @@ func TestPingGet(t *testing.T) {
|
| 38 | 38 |
assert.NilError(t, err) |
| 39 | 39 |
assert.Equal(t, string(b), "OK") |
| 40 | 40 |
assert.Equal(t, res.StatusCode, http.StatusOK) |
| 41 |
- assert.Check(t, hdr(res, "API-Version") != "") |
|
| 41 |
+ assert.Check(t, hdr(res, "Api-Version") != "") |
|
| 42 | 42 |
} |
| 43 | 43 |
|
| 44 | 44 |
func TestPingHead(t *testing.T) {
|
| ... | ... |
@@ -51,7 +51,7 @@ func TestPingHead(t *testing.T) {
|
| 51 | 51 |
assert.NilError(t, err) |
| 52 | 52 |
assert.Equal(t, 0, len(b)) |
| 53 | 53 |
assert.Equal(t, res.StatusCode, http.StatusOK) |
| 54 |
- assert.Check(t, hdr(res, "API-Version") != "") |
|
| 54 |
+ assert.Check(t, hdr(res, "Api-Version") != "") |
|
| 55 | 55 |
} |
| 56 | 56 |
|
| 57 | 57 |
func TestPingSwarmHeader(t *testing.T) {
|