Skip to content

Comments

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

Open
bhamiltoncx wants to merge 3 commits intofacebook:mainfrom
terraware:issue-54626
Open

Fix regression fetching file:// URI scheme in fetch() and XMLHttpRequest requests on Android (#54626)#55706
bhamiltoncx wants to merge 3 commits intofacebook:mainfrom
terraware:issue-54626

Conversation

@bhamiltoncx
Copy link

Summary:

fetch() on file:// URIs is broken on RN Android, but works on RN iOS (#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:

return [request.URL.scheme caseInsensitiveCompare:@"file"] == NSOrderedSame && !RCTIsBundleAssetURL(request.URL);

Android's equivalent BlobModule works correctly to handle file:// URIs, but NetworkingModule was changed in #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 #54626.

The fix is pretty simple: clean up the behavior changed in #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 (#54626)

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"

@meta-cla
Copy link

meta-cla bot commented Feb 23, 2026

Hi @bhamiltoncx!

Thank you for your pull request.

We require contributors to sign our Contributor License Agreement, and yours needs attention.

You currently have a record in our system, but the CLA is no longer valid, and will need to be resubmitted.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@bhamiltoncx bhamiltoncx changed the title Fix regression fetching file:// URI scheme in fetch() and XMLHttpRequest requests (#54626) Fix regression fetching file:// URI scheme in fetch() and XMLHttpRequest requests on Android (#54626) Feb 23, 2026
@meta-cla meta-cla bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Feb 23, 2026
@facebook-github-bot facebook-github-bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Feb 23, 2026
…est requests (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`.

Tested:
  ./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"
@bhamiltoncx
Copy link
Author

@huntie , apologies for the direct ping, but I haven't been at Meta in ages and I don't know how the GitHub -> Phabricator pipeline works these days. :)

Any thoughts on this PR? It fixes a gnarly regression from #52485 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants