Skip to content

Commit 3d78f07

Browse files
huntiereact-native-bot
authored andcommitted
Gate requestBody processing behind BuildConfig.DEBUG (#54920)
Summary: Pull Request resolved: #54920 Gates `requestBody` handling for `reportRequestStart` on Android with `BuildConfig.DEBUG`. This is an appropriate optimisation as we do not use body previews outside of CDP debugging, aligning with the same conditional behaviour on iOS. I'd like to also pick this change for 0.83.1, with D89373824, for additional safety. **Other notes** Gating by `BuildConfig` isn't done elsewhere in this file, as other potentially expensive behaviour is gated lower down by both `REACT_NATIVE_DEBUGGER_ENABLED` and the `Network.enable` CDP message. This was the only remaining gap with the iOS implementation. Changelog: [Internal] Reviewed By: vzaidman Differential Revision: D89377163 fbshipit-source-id: 10a27f6b02f65755d4293f5cf33697d542bc9465
1 parent 471ef72 commit 3d78f07

File tree

1 file changed

+11
-2
lines changed
  • packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/network

1 file changed

+11
-2
lines changed

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/network/NetworkEventUtil.kt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import com.facebook.react.bridge.Arguments
1515
import com.facebook.react.bridge.ReactApplicationContext
1616
import com.facebook.react.bridge.WritableMap
1717
import com.facebook.react.bridge.buildReadableArray
18+
import com.facebook.react.common.build.ReactBuildConfig
1819
import com.facebook.react.internal.featureflags.ReactNativeFeatureFlags
1920
import java.net.SocketTimeoutException
2021
import okhttp3.Headers
@@ -30,13 +31,21 @@ internal object NetworkEventUtil {
3031
fun onCreateRequest(devToolsRequestId: String, request: Request) {
3132
if (ReactNativeFeatureFlags.enableNetworkEventReporting()) {
3233
val headersMap = okHttpHeadersToMap(request.headers())
34+
var requestBody = ""
35+
36+
if (ReactBuildConfig.DEBUG) {
37+
// Debug build: Process request body for preview (CDP only)
38+
requestBody =
39+
(request.body() as? ProgressRequestBody)?.getBodyPreview()
40+
?: request.body()?.toString().orEmpty()
41+
}
42+
3343
InspectorNetworkReporter.reportRequestStart(
3444
devToolsRequestId,
3545
request.url().toString(),
3646
request.method(),
3747
headersMap,
38-
(request.body() as? ProgressRequestBody)?.getBodyPreview()
39-
?: request.body()?.toString().orEmpty(),
48+
requestBody,
4049
request.body()?.contentLength() ?: 0,
4150
)
4251
InspectorNetworkReporter.reportConnectionTiming(devToolsRequestId, headersMap)

0 commit comments

Comments
 (0)