Merge pull request #10249 from jlhawn/distribution_version_header_10247
Split API Version header when checking for v2
This commit is contained in:
commit
b7db855fc6
@ -231,10 +231,13 @@ func (e *Endpoint) pingV2() (RegistryInfo, error) {
|
|||||||
// Ensure it supports the v2 Registry API.
|
// Ensure it supports the v2 Registry API.
|
||||||
var supportsV2 bool
|
var supportsV2 bool
|
||||||
|
|
||||||
for _, versionName := range resp.Header[http.CanonicalHeaderKey("Docker-Distribution-API-Version")] {
|
HeaderLoop:
|
||||||
|
for _, supportedVersions := range resp.Header[http.CanonicalHeaderKey("Docker-Distribution-API-Version")] {
|
||||||
|
for _, versionName := range strings.Fields(supportedVersions) {
|
||||||
if versionName == "registry/2.0" {
|
if versionName == "registry/2.0" {
|
||||||
supportsV2 = true
|
supportsV2 = true
|
||||||
break
|
break HeaderLoop
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,7 +42,9 @@ func TestValidateEndpointAmbiguousAPIVersion(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
requireBasicAuthHandlerV2 := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
requireBasicAuthHandlerV2 := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Header().Add("Docker-Distribution-API-Version", "registry/2.0")
|
// This mock server supports v2.0, v2.1, v42.0, and v100.0
|
||||||
|
w.Header().Add("Docker-Distribution-API-Version", "registry/100.0 registry/42.0")
|
||||||
|
w.Header().Add("Docker-Distribution-API-Version", "registry/2.0 registry/2.1")
|
||||||
requireBasicAuthHandler.ServeHTTP(w, r)
|
requireBasicAuthHandler.ServeHTTP(w, r)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user