[whatwg/fetch] Define how to handele bad content encoding (#657)

I recognized some inconsistencies in the way different fetch implementations handle bad content encoding and couldn't find a clear definition of how to handle it in the spec.

I created a [web-platform-tests](https://github.com/MoritzKn/web-platform-tests/blob/master/fetch/api/basic/bad-content-encoding.html) to track the different behaviors:

| Test case                                                                                  | Chrome      | Edge        | Firefox      | Safari                                            | Github Fetch Polyfill                                          |
| ------------------------------------------------------------------------------------------ | ----------- | ----------- | ------------ | ------------------------------------------------- | -------------------------------------------------------------- |
| Fetching a resource with bad content decoding should still resolve                         | Ok          | Ok          | Ok           | Ok                                                | rejects with `TypeError` ("TypeError: Network request failed") | 
| Consuming the body of a resource with bad content decoding with arrayBuffer() should reject | Ok          | Ok          | Ok           | resolves with an empty `ArrayBuffer` <sup>1</sup> | Ok                                                             |
| arrayBuffer() rejects with error                                                           | `TypeError` | `TypeError` | `AbortError` | /                                                 | `TypeError`                                                    |
| Consuming the body of a resource with bad content decoding with blob() should reject        | Ok          | Ok          | Ok           | resolves with an empty `Blob` <sup>1</sup>        | Ok                                                             |
| blob() rejects with error                                                                  | `TypeError` | `TypeError` | `AbortError` | /                                                 | `TypeError`                                                    |
| Consuming the body of a resource with bad content decoding with formData() should reject    | OK          | OK          | OK           | Ok                                                | OK                                                             |
| formData() rejects with error                                                              | `TypeError` | `TypeError` | `AbortError` | `"Not implemented"`                               | `TypeError`                                                    |
| Consuming the body of a resource with bad content decoding with json() should reject        | Ok          | Ok          | Ok           | Ok <sup>2</sup>                                   | Ok                                                             |
| json() rejects with error                                                                  | `TypeError` | `TypeError` | `AbortError` | `SyntaxError`                                     | `TypeError`                                                    |
| Consuming the body of a resource with bad content decoding with text() should reject        | OK          | OK          | OK           | resolves with an empty string <sup>1</sup>        | OK                                                             |
| text() rejects with error                                                                  | `TypeError` | `TypeError` | `AbortError` | /                                                 | `TypeError`                                                    |

<sup>1</sup> In Safari the `Promise` returned by fetching a resource with bad content encoding only fulfills if it get executed immediately during the load. Otherwise it will never fulfill.
<sup>2</sup> Only rejects because an empty string is no valid JSON ("Syntax Error: (DOM Exception 12): The string did not match the expected pattern.")..


-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/fetch/issues/657

Received on Sunday, 7 January 2018 22:54:34 UTC