Commit 31163eb
Fix regression fetching file:// URI scheme in fetch() and XMLHttpRequest requests on Android (facebook#54626) (facebook#55706)
Summary:
`fetch()` on `file://` URIs is broken on RN Android, but works on RN iOS (facebook#54626).
On Android, `NetworkingModule` powers the implementation of `XMLHttpRequest`, which is the implementation of `fetch()`.
iOS's underlying implementation `RCTNetworking` uses `RCTFileRequestHandler` which correctly supports `file://` URIs:
https://github.com/facebook/react-native/blob/56e1710b73f0011516872bc6a62e52626588839c/packages/react-native/Libraries/Network/RCTFileRequestHandler.mm#L44
Android's equivalent `BlobModule` works correctly to handle `file://` URIs, but `NetworkingModule` was changed in facebook#52485 to construct a `okhttp3.Response`, passing in an `okhttp3.Request` using the `file://` URI.
Unfortunately, `okhttp3.Request.Builder.url()` throws `InvalidArgumentException` whenever given non-HTTP/HTTPS URLs, which caused facebook#54626.
The fix is pretty simple: clean up the behavior changed in facebook#52485 to just pass in the data needed (status code, headers, and content length) rather than trying to wrap it in an `okhttp3.Response`.
## Changelog:
[ANDROID] [FIXED] - file:// URIs passed to fetch() or XMLHttpRequest no longer fail (facebook#54626)
Pull Request resolved: facebook#55706
Test Plan:
Unit tests updated. Ran tests with:
```
./gradlew :packages:react-native:ReactAndroid:testDebugUnitTest \
--tests "com.facebook.react.modules.blob.BlobModuleTest" \
--tests "com.facebook.react.modules.network.NetworkEventUtilTest" \
--tests "com.facebook.react.modules.network.NetworkingModuleTest"
```
Reviewed By: javache
Differential Revision: D94377526
Pulled By: huntie
fbshipit-source-id: 87a9c15cf32c230b916abec2954f28c2a0e444fd1 parent 67c05e1 commit 31163eb
File tree
6 files changed
+182
-59
lines changed- packages/react-native/ReactAndroid/src
- main/java/com/facebook/react/modules
- blob
- network
- test/java/com/facebook/react/modules
- blob
- network
6 files changed
+182
-59
lines changedLines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
66 | | - | |
| 66 | + | |
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
| |||
Lines changed: 20 additions & 19 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
23 | 22 | | |
24 | | - | |
25 | 23 | | |
26 | 24 | | |
27 | 25 | | |
| |||
229 | 227 | | |
230 | 228 | | |
231 | 229 | | |
232 | | - | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
233 | 233 | | |
234 | | - | |
235 | 234 | | |
236 | | - | |
| 235 | + | |
237 | 236 | | |
238 | 237 | | |
239 | 238 | | |
240 | 239 | | |
241 | 240 | | |
242 | 241 | | |
243 | 242 | | |
244 | | - | |
245 | | - | |
246 | | - | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
247 | 246 | | |
248 | 247 | | |
249 | 248 | | |
250 | 249 | | |
251 | 250 | | |
252 | 251 | | |
253 | | - | |
| 252 | + | |
254 | 253 | | |
255 | 254 | | |
256 | 255 | | |
| |||
267 | 266 | | |
268 | 267 | | |
269 | 268 | | |
270 | | - | |
| 269 | + | |
271 | 270 | | |
272 | 271 | | |
273 | 272 | | |
274 | 273 | | |
275 | 274 | | |
276 | 275 | | |
277 | | - | |
| 276 | + | |
278 | 277 | | |
279 | 278 | | |
280 | 279 | | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
281 | 286 | | |
282 | 287 | | |
283 | 288 | | |
284 | 289 | | |
285 | 290 | | |
286 | | - | |
287 | | - | |
288 | | - | |
289 | | - | |
290 | | - | |
291 | | - | |
292 | | - | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
293 | 294 | | |
294 | 295 | | |
295 | 296 | | |
296 | | - | |
| 297 | + | |
297 | 298 | | |
298 | 299 | | |
299 | 300 | | |
| |||
Lines changed: 6 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
39 | | - | |
40 | 39 | | |
41 | 40 | | |
42 | 41 | | |
| |||
310 | 309 | | |
311 | 310 | | |
312 | 311 | | |
313 | | - | |
314 | | - | |
315 | | - | |
316 | | - | |
317 | | - | |
318 | | - | |
319 | | - | |
320 | | - | |
321 | | - | |
322 | 312 | | |
323 | 313 | | |
324 | 314 | | |
325 | 315 | | |
326 | 316 | | |
327 | | - | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
328 | 320 | | |
329 | 321 | | |
330 | 322 | | |
| |||
645 | 637 | | |
646 | 638 | | |
647 | 639 | | |
648 | | - | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
649 | 643 | | |
650 | 644 | | |
651 | 645 | | |
| |||
packages/react-native/ReactAndroid/src/test/java/com/facebook/react/modules/blob/BlobModuleTest.kt
Lines changed: 80 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
| 15 | + | |
| 16 | + | |
14 | 17 | | |
15 | 18 | | |
16 | 19 | | |
| |||
20 | 23 | | |
21 | 24 | | |
22 | 25 | | |
| 26 | + | |
23 | 27 | | |
24 | 28 | | |
25 | 29 | | |
26 | | - | |
| 30 | + | |
27 | 31 | | |
28 | 32 | | |
29 | 33 | | |
| 34 | + | |
30 | 35 | | |
31 | 36 | | |
32 | 37 | | |
33 | 38 | | |
34 | 39 | | |
35 | 40 | | |
36 | 41 | | |
37 | | - | |
| 42 | + | |
| 43 | + | |
38 | 44 | | |
39 | 45 | | |
40 | 46 | | |
| |||
136 | 142 | | |
137 | 143 | | |
138 | 144 | | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
139 | 217 | | |
Lines changed: 13 additions & 25 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | 19 | | |
24 | 20 | | |
25 | 21 | | |
| |||
265 | 261 | | |
266 | 262 | | |
267 | 263 | | |
268 | | - | |
| 264 | + | |
269 | 265 | | |
270 | 266 | | |
271 | | - | |
272 | | - | |
273 | | - | |
274 | | - | |
275 | | - | |
276 | | - | |
277 | | - | |
278 | | - | |
279 | | - | |
280 | 267 | | |
281 | 268 | | |
282 | 269 | | |
283 | 270 | | |
284 | 271 | | |
285 | | - | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
286 | 275 | | |
287 | 276 | | |
288 | 277 | | |
| |||
306 | 295 | | |
307 | 296 | | |
308 | 297 | | |
309 | | - | |
310 | | - | |
311 | | - | |
312 | | - | |
313 | | - | |
314 | | - | |
315 | | - | |
316 | | - | |
317 | | - | |
318 | 298 | | |
319 | 299 | | |
320 | 300 | | |
| |||
336 | 316 | | |
337 | 317 | | |
338 | 318 | | |
339 | | - | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
340 | 328 | | |
341 | 329 | | |
342 | 330 | | |
| |||
0 commit comments