@@ -378,6 +378,40 @@ class NetworkEventUtilTest {
378378 assertThat(preview).isEqualTo(" [Binary data, 512 bytes]" )
379379 }
380380
381+ @Test
382+ fun testGetRequestBodyPreviewDoesNotConsumeMultipartOneShotStream () {
383+ // Regression guard: previewMultipartWithBinaryParts must not call writeTo() on a
384+ // one-shot part. If it ever does, the underlying stream will be drained and the
385+ // real upload will fail at request time.
386+ val fileBytes = ByteArray (2048 ) { it.toByte() }
387+ val stream = ByteArrayInputStream (fileBytes)
388+ val streamingPart =
389+ RequestBodyUtil .create(MediaType .parse(" application/octet-stream" ), stream)
390+ val body =
391+ MultipartBody .Builder (" test-boundary" )
392+ .setType(MultipartBody .FORM )
393+ .addFormDataPart(" description" , " an image" )
394+ .addFormDataPart(" file" , " photo.jpg" , streamingPart)
395+ .build()
396+
397+ NetworkEventUtil .getRequestBodyPreview(body)
398+
399+ assertThat(stream.available()).isEqualTo(fileBytes.size)
400+ }
401+
402+ @Test
403+ fun testGetRequestBodyPreviewDoesNotConsumeSingleOneShotStream () {
404+ // Regression guard for the top-level one-shot branch: getRequestBodyPreview must
405+ // only read contentLength() / contentType() on a one-shot body, never writeTo().
406+ val fileBytes = ByteArray (512 ) { it.toByte() }
407+ val stream = ByteArrayInputStream (fileBytes)
408+ val body = RequestBodyUtil .create(MediaType .parse(" application/octet-stream" ), stream)
409+
410+ NetworkEventUtil .getRequestBodyPreview(body)
411+
412+ assertThat(stream.available()).isEqualTo(fileBytes.size)
413+ }
414+
381415 @Test
382416 fun testNullReactContext () {
383417 val url = " http://example.com"
0 commit comments