mirror of
https://github.com/rclone/rclone.git
synced 2024-11-23 10:59:18 +08:00
yandex: Fix socket leaks
This commit is contained in:
parent
82b85431bd
commit
9ade179407
|
@ -107,7 +107,7 @@ func runRequest(client *Client, req *http.Request) ([]byte, error) {
|
|||
return runRequestWithErrorHandler(client, req, defaultErrorHandler)
|
||||
}
|
||||
|
||||
func runRequestWithErrorHandler(client *Client, req *http.Request, errorHandler ErrorHandler) ([]byte, error) {
|
||||
func runRequestWithErrorHandler(client *Client, req *http.Request, errorHandler ErrorHandler) (out []byte, err error) {
|
||||
resp, err := client.HTTPClient.Do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -28,7 +28,7 @@ func (c *Client) SetCustomProperty(remotePath string, property string, value str
|
|||
}
|
||||
|
||||
//SetCustomPropertyRequest will make an CustomProperty request and return a URL to CustomProperty data to.
|
||||
func (c *Client) SetCustomPropertyRequest(remotePath string, body io.Reader) error {
|
||||
func (c *Client) SetCustomPropertyRequest(remotePath string, body io.Reader) (err error) {
|
||||
values := url.Values{}
|
||||
values.Add("path", remotePath)
|
||||
req, err := c.scopedRequest("PATCH", "/v1/disk/resources?"+values.Encode(), body)
|
||||
|
@ -43,6 +43,7 @@ func (c *Client) SetCustomPropertyRequest(remotePath string, body io.Reader) err
|
|||
if err := CheckAPIError(resp); err != nil {
|
||||
return err
|
||||
}
|
||||
defer CheckClose(resp.Body, &err)
|
||||
|
||||
//If needed we can read response and check if custom_property is set.
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ func (c *Client) Download(remotePath string) (io.ReadCloser, error) { //io.Write
|
|||
}
|
||||
|
||||
// DownloadRequest will make an download request and return a URL to download data to.
|
||||
func (c *Client) DownloadRequest(remotePath string) (*DownloadResponse, error) {
|
||||
func (c *Client) DownloadRequest(remotePath string) (ur *DownloadResponse, err error) {
|
||||
values := url.Values{}
|
||||
values.Add("path", remotePath)
|
||||
|
||||
|
@ -41,7 +41,7 @@ func (c *Client) DownloadRequest(remotePath string) (*DownloadResponse, error) {
|
|||
}
|
||||
defer CheckClose(resp.Body, &err)
|
||||
|
||||
ur, err := ParseDownloadResponse(resp.Body)
|
||||
ur, err = ParseDownloadResponse(resp.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -41,20 +41,20 @@ func ProccessErrorResponse(data io.Reader) (*ErrorResponse, error) {
|
|||
}
|
||||
|
||||
// CheckAPIError is a convenient function to turn erroneous
|
||||
// API response into go error.
|
||||
func CheckAPIError(resp *http.Response) error {
|
||||
// API response into go error. It closes the Body on error.
|
||||
func CheckAPIError(resp *http.Response) (err error) {
|
||||
if resp.StatusCode >= 200 && resp.StatusCode < 400 {
|
||||
return nil
|
||||
}
|
||||
|
||||
defer CheckClose(resp.Body, &err)
|
||||
|
||||
errorResponse, err := ProccessErrorResponse(resp.Body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
errorResponse.StatusCode = resp.StatusCode
|
||||
|
||||
defer CheckClose(resp.Body, &err)
|
||||
|
||||
return errorResponse
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ import (
|
|||
)
|
||||
|
||||
// PerformDownload does the actual download via unscoped PUT request.
|
||||
func (c *Client) PerformDownload(url string) (io.ReadCloser, error) {
|
||||
func (c *Client) PerformDownload(url string) (out io.ReadCloser, err error) {
|
||||
req, err := http.NewRequest("GET", url, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -22,11 +22,11 @@ func (c *Client) PerformDownload(url string) (io.ReadCloser, error) {
|
|||
}
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
defer CheckClose(resp.Body, &err)
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer CheckClose(resp.Body, &err)
|
||||
return nil, fmt.Errorf("download error [%d]: %s", resp.StatusCode, string(body[:]))
|
||||
}
|
||||
return resp.Body, err
|
||||
|
|
|
@ -10,7 +10,7 @@ import (
|
|||
)
|
||||
|
||||
// PerformUpload does the actual upload via unscoped PUT request.
|
||||
func (c *Client) PerformUpload(url string, data io.Reader) error {
|
||||
func (c *Client) PerformUpload(url string, data io.Reader) (err error) {
|
||||
req, err := http.NewRequest("PUT", url, data)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
@ -31,7 +31,7 @@ func (c *Client) Upload(data io.Reader, remotePath string, overwrite bool) error
|
|||
}
|
||||
|
||||
// UploadRequest will make an upload request and return a URL to upload data to.
|
||||
func (c *Client) UploadRequest(remotePath string, overwrite bool) (*UploadResponse, error) {
|
||||
func (c *Client) UploadRequest(remotePath string, overwrite bool) (ur *UploadResponse, err error) {
|
||||
values := url.Values{}
|
||||
values.Add("path", remotePath)
|
||||
values.Add("overwrite", strconv.FormatBool(overwrite))
|
||||
|
@ -50,7 +50,7 @@ func (c *Client) UploadRequest(remotePath string, overwrite bool) (*UploadRespon
|
|||
}
|
||||
defer CheckClose(resp.Body, &err)
|
||||
|
||||
ur, err := ParseUploadResponse(resp.Body)
|
||||
ur, err = ParseUploadResponse(resp.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user