func NewHTTPBlobOpener(hostnameVerification bool) func(*url.URL) (io.ReadCloser, error) {
	return func(url *url.URL) (io.ReadCloser, error) {
		// TODO(rog) make the download operation interruptible.
		client := jujuhttp.NewClient(
			jujuhttp.WithSkipHostnameVerification(!hostnameVerification),
		)

		resp, err := client.Get(context.TODO(), url.String())
		if err != nil {
			return nil, err
		}
		if resp.StatusCode != http.StatusOK {
			// resp.Body is always non-nil. (see https://golang.org/pkg/net/http/#Response)
			_ = resp.Body.Close()

			// Blob is pending to be downloaded
			if resp.StatusCode == http.StatusConflict {
				return nil, errors.NotYetAvailablef("blob contents")
			}
			return nil, errors.Errorf("bad http response: %v", resp.Status)
		}
		return resp.Body, nil
	}
}
// NewHTTPBlobOpener returns a blob opener func suitable for use with
// Download. The opener func uses an HTTP client that enforces the
// provided SSL hostname verification policy.
NewHTTPBlobOpener returns a blob opener func suitable for use with
Download. The opener func uses an HTTP client that enforces the
provided SSL hostname verification policy.
// NewHTTPBlobOpener returns a blob opener func suitable for use with // Download . The opener func uses an HTTP client that enforces the // provided SSL hostname verification policy .
func NewHTTPBlobOpener(hostnameVerification bool) func(*url.URL) (io.ReadCloser, error) {
	return func(url *url.URL) (io.ReadCloser, error) {
		client := jujuhttp.NewClient(
			jujuhttp.WithSkipHostnameVerification(!hostnameVerification),
		)
		resp, err := client.Get(context.TODO(), url.String())
		if err != nil {
			return nil, err
		}
		if resp.StatusCode != http.StatusOK {
			_ = resp.Body.Close()
			if resp.StatusCode == http.StatusConflict {
				return nil, errors.NotYetAvailablef("blob contents")
			}
			return nil, errors.Errorf("bad http response: %v", resp.Status)
		}
		return resp.Body, nil
	}
}
func NewHTTPBlobOpener ( hostnameVerification bool ) func ( * url . URL ) ( io . ReadCloser , error ) { return func ( url * url . URL ) ( io . ReadCloser , error ) { client := jujuhttp . NewClient ( jujuhttp . WithSkipHostnameVerification ( ! hostnameVerification ) , ) resp , err := client . Get ( context . TODO ( ) , url . String ( ) ) if err != nil { return nil , err } if resp . StatusCode != http . StatusOK { _ = resp . Body . Close ( ) if resp . StatusCode == http . StatusConflict { return nil , errors . NotYetAvailablef ( " " ) } return nil , errors . Errorf ( " " , resp . Status ) } return resp . Body , nil } }
NewHTTPBlobOpener returns a blob opener func suitable for use with
Download.
NewHTTPBlobOpener returns a blob opener func suitable for use with Download .
// TODO(rog) make the download operation interruptible. // resp.Body is always non-nil. (see https://golang.org/pkg/net/http/#Response) // Blob is pending to be downloaded