Commit 1127e54
Base64-encode binary response bodies in the C++ NetworkingModule (#57214)
Summary:
Pull Request resolved: #57214
The ReactCxxPlatform `NetworkingModule` delivered response bodies to JS verbatim regardless of the requested `responseType`. For binary response types (`responseType` `arraybuffer`, which the JS `XMLHttpRequest` layer maps to the native `base64` type), JS calls `base64.toByteArray()` on the delivered string. Sending the raw bytes therefore caused the payload to be mis-decoded and corrupted — e.g. `JSON.parse` failures on responses fetched as `arraybuffer`.
Encode the body with base64 for `base64` responses, matching the existing Android (`NetworkingModule.kt` via `Base64.encodeToString(..., NO_WRAP)`) and iOS (`RCTNetworking.mm` via `base64EncodedStringWithOptions:0`) implementations. The encoding reuses the shared `react/utils` `base64Encode` helper already used by `jsinspector-modern`. All other response types are delivered unchanged. The per-`responseType` decision lives in a file-local (anonymous-namespace) `encodeResponseBody` helper in `NetworkingModule.cpp`, so it adds no surface to the public C++ API.
Changelog:
[General][Fixed] - Base64-encode binary (arraybuffer/blob) response bodies in the C++ NetworkingModule so they are not corrupted when delivered to JS
Reviewed By: zeyap
Differential Revision: D108440201
fbshipit-source-id: 38467877ff99ce7fe4d55739662faeb15b7e04401 parent dad85ba commit 1127e54
2 files changed
Lines changed: 59 additions & 2 deletions
File tree
- packages/react-native
- ReactCommon/react/utils/tests
- ReactCxxPlatform/react/io
Lines changed: 36 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
Lines changed: 23 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| |||
270 | 271 | | |
271 | 272 | | |
272 | 273 | | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
273 | 294 | | |
274 | 295 | | |
275 | | - | |
| 296 | + | |
276 | 297 | | |
277 | 298 | | |
278 | 299 | | |
279 | 300 | | |
280 | 301 | | |
281 | | - | |
| 302 | + | |
282 | 303 | | |
283 | 304 | | |
284 | 305 | | |
| |||
0 commit comments