Closing response body when fetching link previews (#5181)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
3234f98aec
Коммит
27f76afb28
@@ -4,6 +4,7 @@
|
|||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
@@ -143,3 +144,10 @@ func ReturnStatusOK(w http.ResponseWriter) {
|
|||||||
m[model.STATUS] = model.STATUS_OK
|
m[model.STATUS] = model.STATUS_OK
|
||||||
w.Write([]byte(model.MapToJson(m)))
|
w.Write([]byte(model.MapToJson(m)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func closeBody(r *http.Response) {
|
||||||
|
if r.Body != nil {
|
||||||
|
ioutil.ReadAll(r.Body)
|
||||||
|
r.Body.Close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -668,6 +668,7 @@ func getOpenGraphMetadata(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
og := opengraph.NewOpenGraph()
|
og := opengraph.NewOpenGraph()
|
||||||
|
|
||||||
res, err := http.Get(props["url"].(string))
|
res, err := http.Get(props["url"].(string))
|
||||||
|
defer closeBody(res)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeOpenGraphToResponse(w, og)
|
writeOpenGraphToResponse(w, og)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import (
|
|||||||
"crypto/sha1"
|
"crypto/sha1"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -108,10 +107,3 @@ func generateTurnPassword(username string, secret string) string {
|
|||||||
h.Write([]byte(username))
|
h.Write([]byte(username))
|
||||||
return base64.StdEncoding.EncodeToString(h.Sum(nil))
|
return base64.StdEncoding.EncodeToString(h.Sum(nil))
|
||||||
}
|
}
|
||||||
|
|
||||||
func closeBody(r *http.Response) {
|
|
||||||
if r.Body != nil {
|
|
||||||
ioutil.ReadAll(r.Body)
|
|
||||||
r.Body.Close()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user