mirror of
https://github.com/m1k1o/neko-rooms.git
synced 2026-11-02 22:51:34 -06:00
remove ioutil.
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user