Skip to content

Commit 76a5ca1

Browse files
committed
Accurately reflect the canonical casing of API-Version and OS-Type headers
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 <[email protected]>
1 parent b1c525a commit 76a5ca1

7 files changed

Lines changed: 14 additions & 14 deletions

File tree

api/server/middleware/version.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ func (e versionUnsupportedError) InvalidParameter() {}
6767
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 {
6868
return func(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
6969
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)
7272

7373
apiVersion := vars["version"]
7474
if apiVersion == "" {

api/server/middleware/version_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,6 @@ func TestVersionMiddlewareWithErrorsReturnsHeaders(t *testing.T) {
140140
hdr := resp.Result().Header
141141
assert.Check(t, is.Contains(hdr.Get("Server"), "Docker/1.2.3"))
142142
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))
145145
}

api/swagger.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9626,7 +9626,7 @@ paths:
96269626
type: "string"
96279627
example: "OK"
96289628
headers:
9629-
API-Version:
9629+
Api-Version:
96309630
type: "string"
96319631
description: "Max API Version the server supports"
96329632
Builder-Version:
@@ -9682,7 +9682,7 @@ paths:
96829682
type: "string"
96839683
example: "(empty)"
96849684
headers:
9685-
API-Version:
9685+
Api-Version:
96869686
type: "string"
96879687
description: "Max API Version the server supports"
96889688
Builder-Version:

client/client_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ func TestNegotiateAPIVersionAutomatic(t *testing.T) {
369369
var pingVersion string
370370
httpClient := newMockClient(func(req *http.Request) (*http.Response, error) {
371371
resp := &http.Response{StatusCode: http.StatusOK, Header: http.Header{}}
372-
resp.Header.Set("API-Version", pingVersion)
372+
resp.Header.Set("Api-Version", pingVersion)
373373
resp.Body = io.NopCloser(strings.NewReader("OK"))
374374
return resp, nil
375375
})

client/ping.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ func parsePingResponse(cli *Client, resp serverResponse) (types.Ping, error) {
5656
err := cli.checkResponseErr(resp)
5757
return ping, errdefs.FromStatusCode(err, resp.statusCode)
5858
}
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")
6161
if resp.header.Get("Docker-Experimental") == "true" {
6262
ping.Experimental = true
6363
}

client/ping_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func TestPingFail(t *testing.T) {
2424
resp := &http.Response{StatusCode: http.StatusInternalServerError}
2525
if withHeader {
2626
resp.Header = http.Header{}
27-
resp.Header.Set("API-Version", "awesome")
27+
resp.Header.Set("Api-Version", "awesome")
2828
resp.Header.Set("Docker-Experimental", "true")
2929
resp.Header.Set("Swarm", "inactive")
3030
}
@@ -72,7 +72,7 @@ func TestPingSuccess(t *testing.T) {
7272
client: newMockClient(func(req *http.Request) (*http.Response, error) {
7373
resp := &http.Response{StatusCode: http.StatusOK}
7474
resp.Header = http.Header{}
75-
resp.Header.Set("API-Version", "awesome")
75+
resp.Header.Set("Api-Version", "awesome")
7676
resp.Header.Set("Docker-Experimental", "true")
7777
resp.Header.Set("Swarm", "active/manager")
7878
resp.Body = io.NopCloser(strings.NewReader("OK"))
@@ -121,7 +121,7 @@ func TestPingHeadFallback(t *testing.T) {
121121
resp.StatusCode = tc.status
122122
}
123123
resp.Header = http.Header{}
124-
resp.Header.Add("API-Version", strings.Join(reqs, ", "))
124+
resp.Header.Add("Api-Version", strings.Join(reqs, ", "))
125125
return resp, nil
126126
}),
127127
}

integration/system/ping_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func TestPingGet(t *testing.T) {
3838
assert.NilError(t, err)
3939
assert.Equal(t, string(b), "OK")
4040
assert.Equal(t, res.StatusCode, http.StatusOK)
41-
assert.Check(t, hdr(res, "API-Version") != "")
41+
assert.Check(t, hdr(res, "Api-Version") != "")
4242
}
4343

4444
func TestPingHead(t *testing.T) {
@@ -51,7 +51,7 @@ func TestPingHead(t *testing.T) {
5151
assert.NilError(t, err)
5252
assert.Equal(t, 0, len(b))
5353
assert.Equal(t, res.StatusCode, http.StatusOK)
54-
assert.Check(t, hdr(res, "API-Version") != "")
54+
assert.Check(t, hdr(res, "Api-Version") != "")
5555
}
5656

5757
func TestPingSwarmHeader(t *testing.T) {

0 commit comments

Comments
 (0)