github.com/michael-k/docker@v1.7.0-rc2/pkg/httputils/httputils.go (about)

     1  package httputils
     2  
     3  import (
     4  	"fmt"
     5  	"net/http"
     6  
     7  	"github.com/docker/docker/pkg/jsonmessage"
     8  )
     9  
    10  // Request a given URL and return an io.Reader
    11  func Download(url string) (resp *http.Response, err error) {
    12  	if resp, err = http.Get(url); err != nil {
    13  		return nil, err
    14  	}
    15  	if resp.StatusCode >= 400 {
    16  		return nil, fmt.Errorf("Got HTTP status code >= 400: %s", resp.Status)
    17  	}
    18  	return resp, nil
    19  }
    20  
    21  func NewHTTPRequestError(msg string, res *http.Response) error {
    22  	return &jsonmessage.JSONError{
    23  		Message: msg,
    24  		Code:    res.StatusCode,
    25  	}
    26  }