Skip to content

Android: Fetch dont't work with "deflate" encoded responses.json() #15693

@DeFenceD

Description

@DeFenceD

Is this a bug report?

Yes
Android use fetch dont't work with "deflate" encoded responses.json().
I copy the same fetch in browser try to it will response the right encoded json.

Environment

  1. react-native -v: 0.47.2
  2. node -v: 8.0.0
  3. npm -v: 5.3.0

Then, specify:

  • Target Platform: Android

  • Development Operating System: Windows

  • Build tools: Android SDK

Steps to Reproduce

fetch(url, {
              method: 'POST',
              headers: {
                'Accept': 'application/json',
                'Content-Type': 'application/json;charset=UTF-8',
              },
              body: JSON.stringify(options),
              compress: true,
            })
              .then((response) => {
                console.log(response);
                return response.json();
              })
              .then((result) => {
                  // result is messy code
              });

Expected Behavior

right to encoded.

Actual Behavior

return messy code

Reproducible Demo

Unhandled Promise Rejection (id: 0):
SyntaxError: Unexpected token { in JSON at position 0
at parse (<anonymous>)
    at tryCallOne (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:13773:12)
    at http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:13859:15
    at http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:5290:19
    at _callTimer (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:5204:7)
    at Object.callImmediatesPass (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:5432:9)
    at Object.callImmediates (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:5443:21)
    at MessageQueue.__callImmediates (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:4803:16)
    at http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:4689:16
    at MessageQueue.__guard (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:4789:9)

Metadata

Metadata

Assignees

No one assigned

    Labels

    StaleThere has been a lack of activity on this issue and it may be closed soon.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions