react-native icon indicating copy to clipboard operation
react-native copied to clipboard

Fetch with gzipped response returns assertion as body() on Android

Open danhawkes opened this issue 10 years ago • 5 comments

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

danhawkes avatar Mar 04 '16 11:03 danhawkes

@lexs - based on NetworkingModule blame this seems up your alley, please re-assign if I'm mistaken :)

brentvatne avatar Mar 06 '16 21:03 brentvatne

@facebook-github-bot label Android

brentvatne avatar Mar 06 '16 22:03 brentvatne

@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 avatar Mar 07 '16 14:03 lexs

@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.

danhawkes avatar Mar 07 '16 15:03 danhawkes

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.

danhawkes avatar Mar 07 '16 15:03 danhawkes