registry: v1Endpoint.ping: don't io.Readall the response

We have the response available, which is an io.Reader, so we don't have
to read the entire response into memory before decoding.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2023-09-08 12:24:27 +02:00
parent e9ad878df6
commit 0c6f8f9290
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C

View file

@ -4,7 +4,6 @@ import (
"context"
"crypto/tls"
"encoding/json"
"io"
"net/http"
"net/url"
"strings"
@ -150,17 +149,12 @@ func (e *v1Endpoint) ping() (v1PingResult, error) {
return info, nil
}
jsonString, err := io.ReadAll(resp.Body)
if err != nil {
return v1PingResult{}, invalidParamWrapf(err, "error while reading response from %s", pingURL)
}
// If the header is absent, we assume true for compatibility with earlier
// versions of the registry. default to true
info := v1PingResult{
Standalone: true,
}
if err := json.Unmarshal(jsonString, &info); err != nil {
if err := json.NewDecoder(resp.Body).Decode(&info); err != nil {
log.G(context.TODO()).WithError(err).Debug("error unmarshaling _ping response")
// don't stop here. Just assume sane defaults
}