Add options for Open and implement Range for all remotes

This commit is contained in:
Nick Craig-Wood
2016-10-05 21:03:56 +01:00
parent 75e5e59385
commit aef2ac5c04
33 changed files with 547 additions and 78 deletions
+9 -3
View File
@@ -8,13 +8,18 @@ import (
"github.com/pkg/errors"
)
// PerformDownload does the actual download via unscoped PUT request.
func (c *Client) PerformDownload(url string) (out io.ReadCloser, err error) {
// PerformDownload does the actual download via unscoped GET request.
func (c *Client) PerformDownload(url string, headers map[string]string) (out io.ReadCloser, err error) {
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return nil, err
}
// Set any extra headers
for k, v := range headers {
req.Header.Set(k, v)
}
//c.setRequestScope(req)
resp, err := c.HTTPClient.Do(req)
@@ -22,7 +27,8 @@ func (c *Client) PerformDownload(url string) (out io.ReadCloser, err error) {
return nil, err
}
if resp.StatusCode != 200 {
_, isRanging := req.Header["Range"]
if !(resp.StatusCode == http.StatusOK || (isRanging && resp.StatusCode == http.StatusPartialContent)) {
defer CheckClose(resp.Body, &err)
body, err := ioutil.ReadAll(resp.Body)
if err != nil {