Closed
Description
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 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 1 |
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 1 |
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 2 | 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 1 | OK |
text() rejects with error | TypeError |
TypeError |
AbortError |
/ | TypeError |
1 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.
2 Only rejects because an empty string isn't valid JSON ("Syntax Error: (DOM Exception 12): The string did not match the expected pattern.").