From 70cf13cae3649c99be414eba08341b516c0f9b10 Mon Sep 17 00:00:00 2001 From: Brandon Croft Date: Thu, 7 Sep 2023 14:42:07 -0600 Subject: [PATCH] cloud: don't update snapshot interval unless response is from tfe.v2 --- internal/cloud/state.go | 8 ++++++++ internal/cloud/testing.go | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/internal/cloud/state.go b/internal/cloud/state.go index dd464e56d0..55e37d8634 100644 --- a/internal/cloud/state.go +++ b/internal/cloud/state.go @@ -584,6 +584,13 @@ func clamp(val, min, max int64) int64 { } func (s *State) readSnapshotIntervalHeader(status int, header http.Header) { + // Only proceed if this came from tfe.v2 API + contentType := header.Get("Content-Type") + if !strings.Contains(contentType, tfe.ContentTypeJSONAPI) { + log.Printf("[TRACE] Skipping intermediate state interval because Content-Type was %q", contentType) + return + } + intervalStr := header.Get(HeaderSnapshotInterval) if intervalSecs, err := strconv.ParseInt(intervalStr, 10, 64); err == nil { @@ -600,6 +607,7 @@ func (s *State) readSnapshotIntervalHeader(status int, header http.Header) { } // We will only enable snapshots for intervals greater than zero + log.Printf("[TRACE] Intermediate state interval is set by header to %v", s.stateSnapshotInterval) s.enableIntermediateSnapshots = s.stateSnapshotInterval > 0 } diff --git a/internal/cloud/testing.go b/internal/cloud/testing.go index 247b1907b6..c05ffdf79d 100644 --- a/internal/cloud/testing.go +++ b/internal/cloud/testing.go @@ -437,7 +437,7 @@ func testServerWithSnapshotsEnabled(t *testing.T, enabled bool) *httptest.Server t.Fatal(err) } - w.Header().Set("content-type", "application/json") + w.Header().Set("content-type", tfe.ContentTypeJSONAPI) w.Header().Set("content-length", strconv.FormatInt(int64(len(fakeBodyRaw)), 10)) switch r.Method {