So I’m trying to do a basic http-fetch, with fetch()
.
<JavaScript>
fetch(
'http://localhost:8181/example.php',
{
method: "POST"
}
).then(function(response) {
console.log("Got response");
return response.json();
}).then(function(jsonResponse) {
console.log("Got JSON response");
// ...
}).catch(function(error) {
console.log("Error: " + error.message);
});
</JavaScript>
The expected result is “Got response”, “Got JSON response”, or “Error: …” if the JSON-parser fails.
However, if the server uses chunked transfer encoding, nothing happens. None of the promises are resolved.
I’ve written a proof of concept-server with PHP with lots of less useful headers, but to mimic a real setup:
<?php
header("Server: nginx");
header("Date: Fri, 27 Nov 2015 07:57:27 GMT");
header("Content-Type: application/json");
header("Transfer-Encoding: chunked"); // *
header("Connection: keep-alive");
header("X-Powered-By: PHP/5.5.28");
header("Set-Cookie: SESSION=860716851feee53429d43d6ec520ac9e; path=/; domain=.somesite.dev; HttpOnly");
header("Access-Control-Allow-Origin: ");
header("Vary: Accept-Encoding");
$data = '{"message":"One chunked result."}';
echo strlen($data)."\r\n";
echo $data."\r\n";
This server can be loaded with php -S 0:8181 example.php
on a usual OS X setup.
If we remove the the “Transfer-Encoding” header and the string length output, the requests works as expected in fetch()
.
Fuse version 0.9.2 (build 5183)