Fix regression fetching file:// URI scheme in fetch() and XMLHttpRequest requests on Android (#54626)#55706
Fix regression fetching file:// URI scheme in fetch() and XMLHttpRequest requests on Android (#54626)#55706bhamiltoncx wants to merge 3 commits intofacebook:mainfrom
Conversation
|
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. ProcessIn 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 If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
fc99fc2 to
07a3d92
Compare
…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"
07a3d92 to
b9d13be
Compare
Summary:
fetch()onfile://URIs is broken on RN Android, but works on RN iOS (#54626).On Android,
NetworkingModulepowers the implementation ofXMLHttpRequest, which is the implementation offetch().iOS's underlying implementation
RCTNetworkingusesRCTFileRequestHandlerwhich correctly supportsfile://URIs:react-native/packages/react-native/Libraries/Network/RCTFileRequestHandler.mm
Line 44 in 56e1710
Android's equivalent
BlobModuleworks correctly to handlefile://URIs, butNetworkingModulewas changed in #52485 to construct aokhttp3.Response, passing in anokhttp3.Requestusing thefile://URI.Unfortunately,
okhttp3.Request.Builder.url()throwsInvalidArgumentExceptionwhenever 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: