forked from TrueCloudLab/rclone
http: fix socket leak on 404 errors
This commit is contained in:
parent
e62bbf761b
commit
bb5ac8efbe
1 changed files with 5 additions and 3 deletions
|
@ -326,14 +326,16 @@ func (f *Fs) readDir(dir string) (names []string, err error) {
|
||||||
return nil, errors.Errorf("internal error: readDir URL %q didn't end in /", URL)
|
return nil, errors.Errorf("internal error: readDir URL %q didn't end in /", URL)
|
||||||
}
|
}
|
||||||
res, err := f.httpClient.Get(URL)
|
res, err := f.httpClient.Get(URL)
|
||||||
if err == nil && res.StatusCode == http.StatusNotFound {
|
if err == nil {
|
||||||
return nil, fs.ErrorDirNotFound
|
defer fs.CheckClose(res.Body, &err)
|
||||||
|
if res.StatusCode == http.StatusNotFound {
|
||||||
|
return nil, fs.ErrorDirNotFound
|
||||||
|
}
|
||||||
}
|
}
|
||||||
err = statusError(res, err)
|
err = statusError(res, err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "failed to readDir")
|
return nil, errors.Wrap(err, "failed to readDir")
|
||||||
}
|
}
|
||||||
defer fs.CheckClose(res.Body, &err)
|
|
||||||
|
|
||||||
contentType := strings.SplitN(res.Header.Get("Content-Type"), ";", 2)[0]
|
contentType := strings.SplitN(res.Header.Get("Content-Type"), ";", 2)[0]
|
||||||
switch contentType {
|
switch contentType {
|
||||||
|
|
Loading…
Reference in a new issue