mirror of
https://github.com/facebook/react-native.git
synced 2026-11-18 20:19:07 +00:00
Fix multipart/form-data request payload previews on Android (#54804)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/54804 Resolves https://github.com/facebook/react-native/issues/54796#issuecomment-3616644916. Fixes a bug where for `multipart/form-data` requests on Android, request payload previews were not using a correctly serialized preview string in React Native DevTools. Changelog: [Internal] Reviewed By: vzaidman Differential Revision: D88495615 fbshipit-source-id: 757487b3588372404fa45f980e0bcfae5c7c6457
This commit is contained in:
1 parent
75f4c83828
commit
8a9a3592a7
2 files changed
+22
-1
No files matched your search
+2
-1
@@ -35,7 +35,8 @@ internal object NetworkEventUtil {
|
||||
request.url().toString(),
|
||||
request.method(),
|
||||
headersMap,
|
||||
request.body()?.toString().orEmpty(),
|
||||
(request.body() as? ProgressRequestBody)?.getBodyPreview()
|
||||
?: request.body()?.toString().orEmpty(),
|
||||
request.body()?.contentLength() ?: 0,
|
||||
)
|
||||
InspectorNetworkReporter.reportConnectionTiming(devToolsRequestId, headersMap)
|
||||
|
||||
+20
@@ -23,6 +23,10 @@ internal class ProgressRequestBody(
|
||||
) : RequestBody() {
|
||||
private var contentLength = 0L
|
||||
|
||||
companion object {
|
||||
private const val MAX_BODY_PREVIEW_SIZE = 1024 * 1024 // 1MB
|
||||
}
|
||||
|
||||
override fun contentType(): MediaType? {
|
||||
return requestBody.contentType()
|
||||
}
|
||||
@@ -78,4 +82,20 @@ internal class ProgressRequestBody(
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
fun getBodyPreview(): String {
|
||||
return try {
|
||||
val buffer = okio.Buffer()
|
||||
requestBody.writeTo(buffer)
|
||||
val size = buffer.size()
|
||||
if (size <= MAX_BODY_PREVIEW_SIZE) {
|
||||
buffer.readUtf8()
|
||||
} else {
|
||||
buffer.readUtf8(MAX_BODY_PREVIEW_SIZE.toLong()) +
|
||||
"\n... [truncated, showing $MAX_BODY_PREVIEW_SIZE of $size bytes]"
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
""
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user