|
@@ -225,8 +225,8 @@ func (r *Session) GetRemoteHistory(imgID, registry string) ([]string, error) {
|
|
return nil, err
|
|
return nil, err
|
|
}
|
|
}
|
|
defer res.Body.Close()
|
|
defer res.Body.Close()
|
|
- if res.StatusCode != 200 {
|
|
|
|
- if res.StatusCode == 401 {
|
|
|
|
|
|
+ if res.StatusCode != http.StatusOK {
|
|
|
|
+ if res.StatusCode == http.StatusUnauthorized {
|
|
return nil, errcode.ErrorCodeUnauthorized.WithArgs()
|
|
return nil, errcode.ErrorCodeUnauthorized.WithArgs()
|
|
}
|
|
}
|
|
return nil, newJSONError(fmt.Sprintf("Server error: %d trying to fetch remote history for %s", res.StatusCode, imgID), res)
|
|
return nil, newJSONError(fmt.Sprintf("Server error: %d trying to fetch remote history for %s", res.StatusCode, imgID), res)
|
|
@@ -248,7 +248,7 @@ func (r *Session) LookupRemoteImage(imgID, registry string) error {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
res.Body.Close()
|
|
res.Body.Close()
|
|
- if res.StatusCode != 200 {
|
|
|
|
|
|
+ if res.StatusCode != http.StatusOK {
|
|
return newJSONError(fmt.Sprintf("HTTP code %d", res.StatusCode), res)
|
|
return newJSONError(fmt.Sprintf("HTTP code %d", res.StatusCode), res)
|
|
}
|
|
}
|
|
return nil
|
|
return nil
|
|
@@ -261,7 +261,7 @@ func (r *Session) GetRemoteImageJSON(imgID, registry string) ([]byte, int64, err
|
|
return nil, -1, fmt.Errorf("Failed to download json: %s", err)
|
|
return nil, -1, fmt.Errorf("Failed to download json: %s", err)
|
|
}
|
|
}
|
|
defer res.Body.Close()
|
|
defer res.Body.Close()
|
|
- if res.StatusCode != 200 {
|
|
|
|
|
|
+ if res.StatusCode != http.StatusOK {
|
|
return nil, -1, newJSONError(fmt.Sprintf("HTTP code %d", res.StatusCode), res)
|
|
return nil, -1, newJSONError(fmt.Sprintf("HTTP code %d", res.StatusCode), res)
|
|
}
|
|
}
|
|
// if the size header is not present, then set it to '-1'
|
|
// if the size header is not present, then set it to '-1'
|
|
@@ -308,7 +308,7 @@ func (r *Session) GetRemoteImageLayer(imgID, registry string, imgSize int64) (io
|
|
statusCode, imgID)
|
|
statusCode, imgID)
|
|
}
|
|
}
|
|
|
|
|
|
- if res.StatusCode != 200 {
|
|
|
|
|
|
+ if res.StatusCode != http.StatusOK {
|
|
res.Body.Close()
|
|
res.Body.Close()
|
|
return nil, fmt.Errorf("Server error: Status %d while fetching image layer (%s)",
|
|
return nil, fmt.Errorf("Server error: Status %d while fetching image layer (%s)",
|
|
res.StatusCode, imgID)
|
|
res.StatusCode, imgID)
|
|
@@ -347,7 +347,7 @@ func (r *Session) GetRemoteTag(registries []string, repositoryRef reference.Name
|
|
if res.StatusCode == 404 {
|
|
if res.StatusCode == 404 {
|
|
return "", ErrRepoNotFound
|
|
return "", ErrRepoNotFound
|
|
}
|
|
}
|
|
- if res.StatusCode != 200 {
|
|
|
|
|
|
+ if res.StatusCode != http.StatusOK {
|
|
continue
|
|
continue
|
|
}
|
|
}
|
|
|
|
|
|
@@ -385,7 +385,7 @@ func (r *Session) GetRemoteTags(registries []string, repositoryRef reference.Nam
|
|
if res.StatusCode == 404 {
|
|
if res.StatusCode == 404 {
|
|
return nil, ErrRepoNotFound
|
|
return nil, ErrRepoNotFound
|
|
}
|
|
}
|
|
- if res.StatusCode != 200 {
|
|
|
|
|
|
+ if res.StatusCode != http.StatusOK {
|
|
continue
|
|
continue
|
|
}
|
|
}
|
|
|
|
|
|
@@ -441,14 +441,14 @@ func (r *Session) GetRepositoryData(name reference.Named) (*RepositoryData, erro
|
|
return nil, fmt.Errorf("Error while pulling image: %v", err)
|
|
return nil, fmt.Errorf("Error while pulling image: %v", err)
|
|
}
|
|
}
|
|
defer res.Body.Close()
|
|
defer res.Body.Close()
|
|
- if res.StatusCode == 401 {
|
|
|
|
|
|
+ if res.StatusCode == http.StatusUnauthorized {
|
|
return nil, errcode.ErrorCodeUnauthorized.WithArgs()
|
|
return nil, errcode.ErrorCodeUnauthorized.WithArgs()
|
|
}
|
|
}
|
|
// TODO: Right now we're ignoring checksums in the response body.
|
|
// TODO: Right now we're ignoring checksums in the response body.
|
|
// In the future, we need to use them to check image validity.
|
|
// In the future, we need to use them to check image validity.
|
|
if res.StatusCode == 404 {
|
|
if res.StatusCode == 404 {
|
|
return nil, newJSONError(fmt.Sprintf("HTTP code: %d", res.StatusCode), res)
|
|
return nil, newJSONError(fmt.Sprintf("HTTP code: %d", res.StatusCode), res)
|
|
- } else if res.StatusCode != 200 {
|
|
|
|
|
|
+ } else if res.StatusCode != http.StatusOK {
|
|
errBody, err := ioutil.ReadAll(res.Body)
|
|
errBody, err := ioutil.ReadAll(res.Body)
|
|
if err != nil {
|
|
if err != nil {
|
|
logrus.Debugf("Error reading response body: %s", err)
|
|
logrus.Debugf("Error reading response body: %s", err)
|
|
@@ -505,7 +505,7 @@ func (r *Session) PushImageChecksumRegistry(imgData *ImgData, registry string) e
|
|
if len(res.Cookies()) > 0 {
|
|
if len(res.Cookies()) > 0 {
|
|
r.client.Jar.SetCookies(req.URL, res.Cookies())
|
|
r.client.Jar.SetCookies(req.URL, res.Cookies())
|
|
}
|
|
}
|
|
- if res.StatusCode != 200 {
|
|
|
|
|
|
+ if res.StatusCode != http.StatusOK {
|
|
errBody, err := ioutil.ReadAll(res.Body)
|
|
errBody, err := ioutil.ReadAll(res.Body)
|
|
if err != nil {
|
|
if err != nil {
|
|
return fmt.Errorf("HTTP code %d while uploading metadata and error when trying to parse response body: %s", res.StatusCode, err)
|
|
return fmt.Errorf("HTTP code %d while uploading metadata and error when trying to parse response body: %s", res.StatusCode, err)
|
|
@@ -539,10 +539,10 @@ func (r *Session) PushImageJSONRegistry(imgData *ImgData, jsonRaw []byte, regist
|
|
return fmt.Errorf("Failed to upload metadata: %s", err)
|
|
return fmt.Errorf("Failed to upload metadata: %s", err)
|
|
}
|
|
}
|
|
defer res.Body.Close()
|
|
defer res.Body.Close()
|
|
- if res.StatusCode == 401 && strings.HasPrefix(registry, "http://") {
|
|
|
|
|
|
+ if res.StatusCode == http.StatusUnauthorized && strings.HasPrefix(registry, "http://") {
|
|
return newJSONError("HTTP code 401, Docker will not send auth headers over HTTP.", res)
|
|
return newJSONError("HTTP code 401, Docker will not send auth headers over HTTP.", res)
|
|
}
|
|
}
|
|
- if res.StatusCode != 200 {
|
|
|
|
|
|
+ if res.StatusCode != http.StatusOK {
|
|
errBody, err := ioutil.ReadAll(res.Body)
|
|
errBody, err := ioutil.ReadAll(res.Body)
|
|
if err != nil {
|
|
if err != nil {
|
|
return newJSONError(fmt.Sprintf("HTTP code %d while uploading metadata and error when trying to parse response body: %s", res.StatusCode, err), res)
|
|
return newJSONError(fmt.Sprintf("HTTP code %d while uploading metadata and error when trying to parse response body: %s", res.StatusCode, err), res)
|
|
@@ -591,7 +591,7 @@ func (r *Session) PushImageLayerRegistry(imgID string, layer io.Reader, registry
|
|
}
|
|
}
|
|
defer res.Body.Close()
|
|
defer res.Body.Close()
|
|
|
|
|
|
- if res.StatusCode != 200 {
|
|
|
|
|
|
+ if res.StatusCode != http.StatusOK {
|
|
errBody, err := ioutil.ReadAll(res.Body)
|
|
errBody, err := ioutil.ReadAll(res.Body)
|
|
if err != nil {
|
|
if err != nil {
|
|
return "", "", newJSONError(fmt.Sprintf("HTTP code %d while uploading metadata and error when trying to parse response body: %s", res.StatusCode, err), res)
|
|
return "", "", newJSONError(fmt.Sprintf("HTTP code %d while uploading metadata and error when trying to parse response body: %s", res.StatusCode, err), res)
|
|
@@ -621,7 +621,7 @@ func (r *Session) PushRegistryTag(remote reference.Named, revision, tag, registr
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
res.Body.Close()
|
|
res.Body.Close()
|
|
- if res.StatusCode != 200 && res.StatusCode != 201 {
|
|
|
|
|
|
+ if res.StatusCode != http.StatusOK && res.StatusCode != http.StatusCreated {
|
|
return newJSONError(fmt.Sprintf("Internal server error: %d trying to push tag %s on %s", res.StatusCode, tag, reference.Path(remote)), res)
|
|
return newJSONError(fmt.Sprintf("Internal server error: %d trying to push tag %s on %s", res.StatusCode, tag, reference.Path(remote)), res)
|
|
}
|
|
}
|
|
return nil
|
|
return nil
|
|
@@ -675,13 +675,13 @@ func (r *Session) PushImageJSONIndex(remote reference.Named, imgList []*ImgData,
|
|
}
|
|
}
|
|
defer res.Body.Close()
|
|
defer res.Body.Close()
|
|
|
|
|
|
- if res.StatusCode == 401 {
|
|
|
|
|
|
+ if res.StatusCode == http.StatusUnauthorized {
|
|
return nil, errcode.ErrorCodeUnauthorized.WithArgs()
|
|
return nil, errcode.ErrorCodeUnauthorized.WithArgs()
|
|
}
|
|
}
|
|
|
|
|
|
var tokens, endpoints []string
|
|
var tokens, endpoints []string
|
|
if !validate {
|
|
if !validate {
|
|
- if res.StatusCode != 200 && res.StatusCode != 201 {
|
|
|
|
|
|
+ if res.StatusCode != http.StatusOK && res.StatusCode != http.StatusCreated {
|
|
errBody, err := ioutil.ReadAll(res.Body)
|
|
errBody, err := ioutil.ReadAll(res.Body)
|
|
if err != nil {
|
|
if err != nil {
|
|
logrus.Debugf("Error reading response body: %s", err)
|
|
logrus.Debugf("Error reading response body: %s", err)
|
|
@@ -699,7 +699,7 @@ func (r *Session) PushImageJSONIndex(remote reference.Named, imgList []*ImgData,
|
|
return nil, err
|
|
return nil, err
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
- if res.StatusCode != 204 {
|
|
|
|
|
|
+ if res.StatusCode != http.StatusNoContent {
|
|
errBody, err := ioutil.ReadAll(res.Body)
|
|
errBody, err := ioutil.ReadAll(res.Body)
|
|
if err != nil {
|
|
if err != nil {
|
|
logrus.Debugf("Error reading response body: %s", err)
|
|
logrus.Debugf("Error reading response body: %s", err)
|
|
@@ -752,7 +752,7 @@ func (r *Session) SearchRepositories(term string, limit int) (*registrytypes.Sea
|
|
return nil, errdefs.System(err)
|
|
return nil, errdefs.System(err)
|
|
}
|
|
}
|
|
defer res.Body.Close()
|
|
defer res.Body.Close()
|
|
- if res.StatusCode != 200 {
|
|
|
|
|
|
+ if res.StatusCode != http.StatusOK {
|
|
return nil, newJSONError(fmt.Sprintf("Unexpected status code %d", res.StatusCode), res)
|
|
return nil, newJSONError(fmt.Sprintf("Unexpected status code %d", res.StatusCode), res)
|
|
}
|
|
}
|
|
result := new(registrytypes.SearchResults)
|
|
result := new(registrytypes.SearchResults)
|