2015-12-07 04:01:03 +00:00
|
|
|
package src
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
"io/ioutil"
|
|
|
|
"net/http"
|
2016-06-12 14:06:02 +00:00
|
|
|
|
|
|
|
"github.com/pkg/errors"
|
2015-12-07 04:01:03 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// PerformDownload does the actual download via unscoped PUT request.
|
2015-12-30 13:30:57 +00:00
|
|
|
func (c *Client) PerformDownload(url string) (out io.ReadCloser, err error) {
|
2015-12-07 04:01:03 +00:00
|
|
|
req, err := http.NewRequest("GET", url, nil)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
//c.setRequestScope(req)
|
|
|
|
|
2016-02-15 16:43:18 +00:00
|
|
|
resp, err := c.HTTPClient.Do(req)
|
2015-12-07 04:01:03 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if resp.StatusCode != 200 {
|
2015-12-30 13:30:57 +00:00
|
|
|
defer CheckClose(resp.Body, &err)
|
2015-12-07 04:01:03 +00:00
|
|
|
body, err := ioutil.ReadAll(resp.Body)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2016-06-12 14:06:02 +00:00
|
|
|
return nil, errors.Errorf("download error [%d]: %s", resp.StatusCode, string(body[:]))
|
2015-12-07 04:01:03 +00:00
|
|
|
}
|
|
|
|
return resp.Body, err
|
|
|
|
}
|