Open up v2 http status code checks for put and head checks

Under certain cases, such as when putting a manifest or check for the existence
of a layer, the status code checks in session_v2.go were too narrow for their
purpose. In the case of putting a manifest, the handler only cares that an
error is not returned. Whether it is a 304 or 202 does not matter, as long as
the server reports success. Having the client only accept specific http codes
inhibits future protocol evolution.

Signed-off-by: Stephen J Day <stephen.day@docker.com>
This commit is contained in:
Stephen J Day 2015-01-27 18:09:53 -08:00
parent b7db855fc6
commit 0818476cb1

View file

@ -124,14 +124,15 @@ func (r *Session) HeadV2ImageBlob(ep *Endpoint, imageName, sumType, sum string,
return false, err return false, err
} }
res.Body.Close() // close early, since we're not needing a body on this call .. yet? res.Body.Close() // close early, since we're not needing a body on this call .. yet?
switch res.StatusCode { switch {
case 200: case res.StatusCode >= 200 && res.StatusCode < 400:
// return something indicating no push needed // return something indicating no push needed
return true, nil return true, nil
case 404: case res.StatusCode == 404:
// return something indicating blob push needed // return something indicating blob push needed
return false, nil return false, nil
} }
return false, utils.NewHTTPRequestError(fmt.Sprintf("Server error: %d trying head request for %s - %s:%s", res.StatusCode, imageName, sumType, sum), res) return false, utils.NewHTTPRequestError(fmt.Sprintf("Server error: %d trying head request for %s - %s:%s", res.StatusCode, imageName, sumType, sum), res)
} }
@ -278,7 +279,9 @@ func (r *Session) PutV2ImageManifest(ep *Endpoint, imageName, tagName string, ma
return err return err
} }
defer res.Body.Close() defer res.Body.Close()
if res.StatusCode != 200 {
// All 2xx and 3xx responses can be accepted for a put.
if res.StatusCode >= 400 {
if res.StatusCode == 401 { if res.StatusCode == 401 {
return errLoginRequired return errLoginRequired
} }