diff --git a/server.go b/server.go index aea18e5..f2c42cb 100644 --- a/server.go +++ b/server.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "fmt" + "io" "log/slog" "math/rand" "net/http" @@ -161,8 +162,13 @@ func (s *Server) pingContainers() { defer rc.Close() config := Config{} - if err := json.NewDecoder(rc).Decode(&config); err != nil { - slog.Error("failed to decode container config", "container_id", c.Id, "url", url, "error", err) + payload, err := io.ReadAll(rc) + if err != nil { + slog.Error("failed to read container config", "container_id", c.Id, "url", url, "error", err) + return + } + if err := json.Unmarshal(payload, &config); err != nil { + slog.Error("failed to decode container config", "container_id", c.Id, "url", url, "error", err, "payload", string(payload)) return } diff --git a/server_test.go b/server_test.go index db3aceb..694bc05 100644 --- a/server_test.go +++ b/server_test.go @@ -22,13 +22,13 @@ func createDummyContainer(t *testing.T, config *baker.Config) *baker.Container { slog.Debug("request", "host", r.Host, "path", r.URL.Path) if r.URL.Path == "/config" { - b, err := json.Marshal(config) if err != nil { t.Fatal(err) } w.WriteHeader(http.StatusOK) w.Write(b) + return } w.WriteHeader(http.StatusOK)