Skip to content

Commit ff5d57f

Browse files
committed
fix(http-cache): honour Clear-Site-Data when a platform response's body read fails
The platform transport returned on a failed body read before it looked at Clear-Site-Data, so a 2xx carrier whose body timed out left the origin's cached modules in place. The header is now processed once the stream is closed, whatever the read did, as on the OkHttp transport.
1 parent e472c4c commit ff5d57f

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

‎test-app/runtime/src/main/cpp/HttpLoader.cpp‎

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -980,15 +980,9 @@ static bool PerformHttpFetchOnceSync(const std::string& url, int timeoutMs, bool
980980
}
981981
}
982982
}
983-
// A truncated read only matters when the body is what the caller
984-
// needs: on a non-2xx the status alone decides the outcome, so keep
985-
// the answer rather than turning it into a retryable network error.
986-
if (readFailed && (!haveStatus || (status >= 200 && status < 300))) {
987-
return false;
988-
}
989-
990-
// Clear-Site-Data, now that the stream is closed. A failure here costs
991-
// only the clear, never the module.
983+
// Clear-Site-Data, now that the stream is closed, and whether or not
984+
// the body arrived whole, as on the OkHttp transport. A failure here
985+
// costs only the clear, never the module.
992986
if (isHttp) {
993987
jclass clsCache = env.FindClass("com/tns/ModuleHttpCache");
994988
jmethodID onResponse =
@@ -1001,6 +995,13 @@ static bool PerformHttpFetchOnceSync(const std::string& url, int timeoutMs, bool
1001995
raw->ExceptionClear();
1002996
}
1003997

998+
// A truncated read only matters when the body is what the caller
999+
// needs: on a non-2xx the status alone decides the outcome, so keep
1000+
// the answer rather than turning it into a retryable network error.
1001+
if (readFailed && (!haveStatus || (status >= 200 && status < 300))) {
1002+
return false;
1003+
}
1004+
10041005
jmethodID getContentType =
10051006
env.GetMethodID(clsConn, "getContentType", "()Ljava/lang/String;");
10061007
jstring jct = static_cast<jstring>(env.CallObjectMethod(conn, getContentType));

0 commit comments

Comments
 (0)