MM-25006: Fix occurences of unclosed http bodies (#14521)

* MM-25006: Fix occurences of unclosed http bodies

And while here, we also use ioutil.Discard to read the remaining
body instead of reading with ioutil.ReadAll which allocates a separate
byte buffer.

* Fix mistake

* Address review comments

Co-authored-by: mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
Agniva De Sarker
2020-05-20 08:41:37 +05:30
коммит произвёл GitHub
родитель ee8bd4ece4
Коммит 15ed9a8f20
7 изменённых файлов: 42 добавлений и 17 удалений

Просмотреть файл

@@ -6,6 +6,8 @@ package api4
import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"runtime"
"strconv"
@@ -432,6 +434,10 @@ func getRedirectLocation(c *Context, w http.ResponseWriter, r *http.Request) {
w.Write([]byte(model.MapToJson(m)))
return
}
defer func() {
io.Copy(ioutil.Discard, res.Body)
res.Body.Close()
}()
location := res.Header.Get("Location")
redirectLocationDataCache.AddWithExpiresInSecs(url, location, 3600) // Expires after 1 hour