Browse Source
Merge pull request #1173 from divinerapier/master
feat: drains http body if buffer is too small
pull/1189/head
Chris Lu
5 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with
9 additions and
1 deletions
-
weed/util/http_util.go
|
|
@ -235,8 +235,16 @@ func ReadUrl(fileUrl string, offset int64, size int, buf []byte, isReadRange boo |
|
|
|
if err != nil { |
|
|
|
return n, err |
|
|
|
} |
|
|
|
if n == int64(len(buf)) { |
|
|
|
break |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// drains the response body to avoid memory leak
|
|
|
|
data, err := ioutil.ReadAll(reader) |
|
|
|
if len(data) != 0 { |
|
|
|
err = fmt.Errorf("buffer size is too small. remains %d", len(data)) |
|
|
|
} |
|
|
|
return n, err |
|
|
|
} |
|
|
|
|
|
|
|
func ReadUrlAsStream(fileUrl string, offset int64, size int, fn func(data []byte)) (int64, error) { |
|
|
|