This commit is contained in:
Thomas E Lackey 2022-09-28 15:30:04 -05:00
parent 36dd5d6331
commit bfaf768d97
2 changed files with 21 additions and 10 deletions

View File

@ -16,9 +16,11 @@
package beaconclient package beaconclient
import ( import (
"bufio"
"bytes"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil" "io"
"net/http" "net/http"
"strconv" "strconv"
"strings" "strings"
@ -71,14 +73,17 @@ func (bc BeaconClient) QueryHeadSync() (Sync, error) {
} }
defer resp.Body.Close() defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body) var body bytes.Buffer
buf := bufio.NewWriter(&body)
_, err = io.Copy(buf, resp.Body)
if err != nil { if err != nil {
return syncStatus, err return syncStatus, err
} }
if err := json.Unmarshal(body, &syncStatus); err != nil { if err := json.Unmarshal(body.Bytes(), &syncStatus); err != nil {
loghelper.LogEndpoint(bcSync).WithFields(log.Fields{ loghelper.LogEndpoint(bcSync).WithFields(log.Fields{
"rawMessage": string(body), "rawMessage": body.String(),
"err": err, "err": err,
}).Error("Unable to unmarshal sync status") }).Error("Unable to unmarshal sync status")
return syncStatus, err return syncStatus, err
@ -149,14 +154,16 @@ func (bc BeaconClient) queryLighthouseDbInfo() (LighthouseDatabaseInfo, error) {
} }
defer resp.Body.Close() defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body) var body bytes.Buffer
buf := bufio.NewWriter(&body)
_, err = io.Copy(buf, resp.Body)
if err != nil { if err != nil {
return dbInfo, err return dbInfo, err
} }
if err := json.Unmarshal(body, &dbInfo); err != nil { if err := json.Unmarshal(body.Bytes(), &dbInfo); err != nil {
loghelper.LogEndpoint(lhDbInfo).WithFields(log.Fields{ loghelper.LogEndpoint(lhDbInfo).WithFields(log.Fields{
"rawMessage": string(body), "rawMessage": body.String(),
"err": err, "err": err,
}).Error("Unable to unmarshal the lighthouse database information") }).Error("Unable to unmarshal the lighthouse database information")
return dbInfo, err return dbInfo, err

View File

@ -18,8 +18,10 @@
package beaconclient package beaconclient
import ( import (
"bufio"
"bytes"
"fmt" "fmt"
"io/ioutil" "io"
"net/http" "net/http"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
@ -59,11 +61,13 @@ func querySsz(endpoint string, slot Slot) ([]byte, int, error) {
return nil, rc, fmt.Errorf("HTTP Error: %d", rc) return nil, rc, fmt.Errorf("HTTP Error: %d", rc)
} }
body, err := ioutil.ReadAll(response.Body) var body bytes.Buffer
buf := bufio.NewWriter(&body)
_, err = io.Copy(buf, response.Body)
if err != nil { if err != nil {
loghelper.LogSlotError(slot.Number(), err).Error("Unable to turn response into a []bytes array!") loghelper.LogSlotError(slot.Number(), err).Error("Unable to turn response into a []bytes array!")
return nil, rc, fmt.Errorf("Unable to turn response into a []bytes array!: %s", err.Error()) return nil, rc, fmt.Errorf("Unable to turn response into a []bytes array!: %s", err.Error())
} }
return body, rc, nil return body.Bytes(), rc, nil
} }