Fix AWS S3 upload failure: remove ClearAllHeaders that was wiping SigV4 state

Removing the Fix 1 ClearAllHeaders/ClearAllQueryParams block from all 8
upload entry points. CkRest.AddHeader already overwrites by header name,
so the clears were unnecessary; they also wipe the internal state
Chilkat's SigV4 signer relies on between requests, which caused AWS to
reject every PUT with HTTP 400 MaxMessageLengthExceeded (max 35240 B).
Per-step ClearAllQueryParams inside multipart kept (followed immediately
by AddQueryParam).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-17 08:13:32 +10:00
parent a63feab0ff
commit fcc985efb9

View File

@@ -628,10 +628,6 @@ namespace ANSCENTER
// Auto-prewarm the connection pool so the first N concurrent uploads
// don't serialize on TLS handshake. No-op if not connected yet.
// Callers wanting a different size can call PrewarmConnectionPool()
// directly at any time — this is just a sensible default that keeps
// existing LabVIEW callers (which only invoke SetAuthentication via
// the C wrapper) warm without any API change on their side.
static constexpr int kDefaultPrewarmCount = 8;
PrewarmConnectionPool(kDefaultPrewarmCount);
@@ -1566,14 +1562,6 @@ namespace ANSCENTER
conn->rest.put_Host(_fullAWSURL.c_str());
}
// Fix 1: the CkRest inside a pooled S3Connection accumulates
// headers and query params across requests. Clear them at the
// start of every attempt so a request can't inherit stale
// state (e.g. Content-Encoding:gzip) from a prior upload on
// this same connection.
conn->rest.ClearAllHeaders();
conn->rest.ClearAllQueryParams();
// Read the file on each attempt (cheap; keeps the body fresh).
CkFileAccess fac;
const char* fileContents = fac.readEntireTextFile(textFilePath.c_str(), "utf-8");
@@ -1665,14 +1653,6 @@ namespace ANSCENTER
conn->rest.put_Host(_fullAWSURL.c_str());
}
// Fix 1: the CkRest inside a pooled S3Connection accumulates
// headers and query params across requests. Clear them at the
// start of every attempt so a request can't inherit stale
// state (e.g. Content-Encoding:gzip) from a prior upload on
// this same connection.
conn->rest.ClearAllHeaders();
conn->rest.ClearAllQueryParams();
CkBinData binData;
if (!binData.LoadFile(dataFilePath.c_str())) {
lastError = std::string("Failed to load file: ") + binData.lastErrorText();
@@ -1775,14 +1755,6 @@ namespace ANSCENTER
conn->rest.put_Host(_fullAWSURL.c_str());
}
// Fix 1: the CkRest inside a pooled S3Connection accumulates
// headers and query params across requests. Clear them at the
// start of every attempt so a request can't inherit stale
// state (e.g. Content-Encoding:gzip) from a prior upload on
// this same connection.
conn->rest.ClearAllHeaders();
conn->rest.ClearAllQueryParams();
CkBinData binData;
if (!binData.LoadFile(dataFilePath.c_str())) {
lastError = std::string("Failed to load file: ") + binData.lastErrorText();
@@ -1858,14 +1830,6 @@ namespace ANSCENTER
conn->rest.put_Host(_fullAWSURL.c_str());
}
// Fix 1: the CkRest inside a pooled S3Connection accumulates
// headers and query params across requests. Clear them at the
// start of every attempt so a request can't inherit stale
// state (e.g. Content-Encoding:gzip) from a prior upload on
// this same connection.
conn->rest.ClearAllHeaders();
conn->rest.ClearAllQueryParams();
// Fresh stream per attempt (it holds OS file handle state).
CkStream fileStream;
fileStream.put_SourceFile(dataFilePath.c_str());
@@ -1979,14 +1943,6 @@ namespace ANSCENTER
conn->rest.put_Host(_fullAWSURL.c_str());
}
// Fix 1: the CkRest inside a pooled S3Connection accumulates
// headers and query params across requests. Clear them at the
// start of every attempt so a request can't inherit stale
// state (e.g. Content-Encoding:gzip) from a prior upload on
// this same connection.
conn->rest.ClearAllHeaders();
conn->rest.ClearAllQueryParams();
// ---- STEP 1: INITIATE ----
conn->rest.ClearAllQueryParams();
conn->rest.AddQueryParam("uploads", "");
@@ -2203,14 +2159,6 @@ namespace ANSCENTER
conn->rest.put_Host(_fullAWSURL.c_str());
}
// Fix 1: the CkRest inside a pooled S3Connection accumulates
// headers and query params across requests. Clear them at the
// start of every attempt so a request can't inherit stale
// state (e.g. Content-Encoding:gzip) from a prior upload on
// this same connection.
conn->rest.ClearAllHeaders();
conn->rest.ClearAllQueryParams();
// ---- STEP 1: INITIATE ----
conn->rest.ClearAllQueryParams();
conn->rest.AddQueryParam("uploads", "");
@@ -2370,14 +2318,6 @@ namespace ANSCENTER
conn->rest.put_Host(_fullAWSURL.c_str());
}
// Fix 1: the CkRest inside a pooled S3Connection accumulates
// headers and query params across requests. Clear them at the
// start of every attempt so a request can't inherit stale
// state (e.g. Content-Encoding:gzip) from a prior upload on
// this same connection.
conn->rest.ClearAllHeaders();
conn->rest.ClearAllQueryParams();
CkBinData binData;
CkByteData jpegBytes;
jpegBytes.append2(jpeg_string, static_cast<unsigned long>(bufferLength));
@@ -2466,14 +2406,6 @@ namespace ANSCENTER
conn->rest.put_Host(_fullAWSURL.c_str());
}
// Fix 1: the CkRest inside a pooled S3Connection accumulates
// headers and query params across requests. Clear them at the
// start of every attempt so a request can't inherit stale
// state (e.g. Content-Encoding:gzip) from a prior upload on
// this same connection.
conn->rest.ClearAllHeaders();
conn->rest.ClearAllQueryParams();
CkBinData binData;
CkByteData jpegBytes;
jpegBytes.append2(jpeg_string, static_cast<unsigned long>(bufferLength));