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