Refactor utils/utils, fixes #11923

Signed-off-by: Antonio Murdaca <me@runcom.ninja>
This commit is contained in:
Antonio Murdaca 2015-03-29 23:17:23 +02:00
parent b15e56b3ef
commit d7a5d5b94c
10 changed files with 328 additions and 10 deletions

26
httputils/httputils.go Normal file
View file

@ -0,0 +1,26 @@
package httputils
import (
"fmt"
"net/http"
"github.com/docker/docker/pkg/jsonmessage"
)
// Request a given URL and return an io.Reader
func Download(url string) (resp *http.Response, err error) {
if resp, err = http.Get(url); err != nil {
return nil, err
}
if resp.StatusCode >= 400 {
return nil, fmt.Errorf("Got HTTP status code >= 400: %s", resp.Status)
}
return resp, nil
}
func NewHTTPRequestError(msg string, res *http.Response) error {
return &jsonmessage.JSONError{
Message: msg,
Code: res.StatusCode,
}
}