remove ioutil.

This commit is contained in:
Miroslav Šedivý
2023-09-30 15:14:57 +02:00
parent 9a63cc21c1
commit 28ec254ff6
+8 -10
View File
@@ -2,7 +2,7 @@ package server
import (
"context"
"io/ioutil"
"io"
"net"
"net/http"
"os"
@@ -129,14 +129,6 @@ func New(ApiManager types.ApiManager, roomConfig *config.Room, config *config.Se
}
defer res.Body.Close()
// read whole body
body, err := ioutil.ReadAll(res.Body)
if err != nil {
logger.Err(err).Msg("proxy auth request `ioutil.ReadAll` err")
http.Error(w, "proxy auth failed", http.StatusForbidden)
return
}
if res.StatusCode < 200 || res.StatusCode >= 300 {
// copy headers
for k, vv := range res.Header {
@@ -147,8 +139,14 @@ func New(ApiManager types.ApiManager, roomConfig *config.Room, config *config.Se
// copy status & body
w.WriteHeader(res.StatusCode)
w.Write(body)
_, err := io.Copy(w, res.Body)
if err != nil {
logger.Err(err).Msg("proxy auth request `io.Copy` err")
}
return
} else {
// discard body so that the connection can be reused
_, _ = io.Copy(io.Discard, res.Body)
}
next.ServeHTTP(w, r)