Fetch with gzipped response returns assertion as body() on Android
Minimal example:
let formData = new FormData();
formData.append('file', {
uri: 'file:///storage/emulated/0/Pictures/RCTCameraModule/IMG_20160304_110411.jpg',
type: 'image/jpg',
name: 'IMG_20160304_110411.jpg'
});
fetch(`https://example.com`, {
method: 'POST',
body: formData
}).then(response => response.text())
.then(body => console.log) // prints `ID1ID2: actual 0x00003c3f != expected 0x00001f8b`
.catch(error => console.log);
OkHttp automatically inserts an Accept-Encoding: gzip header.
The server successfully receives the file and retuns a gzipped response. However, body() returns the above assertion from within OkHttp.
This particular service works fine on iOS, and also OkHttp via the java API on android.
- React native 0.20.0
- Android
@lexs - based on NetworkingModule blame this seems up your alley, please re-assign if I'm mistaken :)
@facebook-github-bot label Android
@danhawkes I can't repro this, I'm running the code below and see the html contents being printed to the console.
let formData = new FormData();
formData.append('file', {
uri: 'file:///sdcard/Download/image.jpg',
type: 'image/jpg',
name: 'image.jpg'
});
fetch(`https://example.com`, {
method: 'POST',
body: formData
}).then(response => response.text())
.then(console.log)
.catch(console.log);
@lexs This may be an issue with our backend - there's a bug in WSO2 where it's adding the gzip header to the response but not actually gzipping the content. Will check and get back to you.
Yep, that's it. Turns out it worked with our 'native' OkHttp code because we're explicitly setting a Accept-Encoding: gzip,deflate, which has the effect of not returning the erroneous header.