-
Notifications
You must be signed in to change notification settings - Fork 24.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HEAD requests fail on Android with 'TypeError: Network request failed' #30055
Comments
I've encountered this issue before - I'm not aware of any workaround other than to use Axios https://github.com/axios/axios This seems to have been an issue for a number of years - #19435 |
#28355 is also a duplicate, just hoping that by adding a bit more context we can give this some visibility :) |
Hi @lachenmayer . |
This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days. |
This issue was closed because it has been stalled for 7 days with no activity. |
Hi team,
Description
On Android, all HTTP HEAD requests for which the server returns a
Content-Length
header fail with a "TypeError: Network request failed". This is reproducible in a brand-new app created usingcreate-react-native-app
, as well as on Expo Snack.React Native version:
This affects React Native 0.63.2. Click here to expand full
react-native info
output.Steps To Reproduce
(Try this out in the Expo Snack)
Perform the following fetch call:
await fetch('https://determined-panini-990054.netlify.app/demo-image.png', { method: 'HEAD' })
. Any URL where the server returns aContent-Length
header will do.Expected result: Fetch promise should resolve with an 'ok' response.
Actual result: On Android, the fetch promise rejects with
TypeError: Network request failed
. On iOS, the fetch promise resolves as expected.Snack, code example, screenshot, or link to a repository:
create-react-native-app
: https://github.com/lachenmayer/react-native-android-fetch-head-reproInvestigation
Click here for in-depth investigation.
Following the stack trace that's triggered in the repro app, the promise rejection is caused by the
XMLHTTPRequest
'sonerror
callback.The XMLHTTPRequest implementation is in
Libraries/Network/XMLHTTPRequest.js
. Adding the following log statement in the__didCompleteResponse
method:...results in the following error being logged:
The
Content-Length
of the demo image I uploaded is indeed9306
, which can be verified in a browser by looking at the response. As the request is aHEAD
request, it is expected that the stream length is 0.Digging deeper, it seems that this exception is thrown by
OkHttp
: https://github.com/square/okhttp/blob/19771365f25d986d125478a75c15d24d6e285e12/okhttp/src/main/kotlin/okhttp3/ResponseBody.kt#L148My initial hunch (see above) is that this is caused by an issue in
OkHttp
, but I've decided to open this here, as this breaks a core part of React Native. This affects us severely currently, as there's not really any way we can change how we make HTTP requests, so would appreciate any pointers.Thanks a lot for your help 😊
The text was updated successfully, but these errors were encountered: