SIGN IN SIGN UP
facebook / react-native UNCLAIMED

A framework for building native applications using React

0 0 0 C++

Fix regression fetching file:// URI scheme in fetch() and XMLHttpRequest requests on Android (#54626) (#55706)

Summary:
`fetch()` on `file://` URIs is broken on RN Android, but works on RN iOS (https://github.com/facebook/react-native/issues/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 https://github.com/facebook/react-native/issues/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 https://github.com/facebook/react-native/issues/54626.

The fix is pretty simple: clean up the behavior changed in https://github.com/facebook/react-native/issues/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 (https://github.com/facebook/react-native/issues/54626)

Pull Request resolved: https://github.com/facebook/react-native/pull/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: 87a9c15cf32c230b916abec2954f28c2a0e444fd
B
Ben Hamilton committed
e76a6e2ef4bfd2cf9e10a4a2ffe21bd1b2c981a9
Parent: d1b2ddc
Committed by meta-codesync[bot] <215208954+meta-codesync[bot]@users.noreply.github.com> on 2/26/2026, 1:06:46 PM