chrisjoyce911 / esp32FOTA

Experiments in firmware OTA updates for ESP32 dev boards
The Unlicense
358 stars 86 forks source link

InvalidInput when decoding manifest due to HTTP 1.1 call #131

Closed sschueller closed 1 month ago

sschueller commented 1 year ago

Returning the json manifest from my web server running a fairly new nginx version I get "InvalidInput" when decoding the json with a length of -1.

This appears to be due to https://arduinojson.org/v6/how-to/use-arduinojson-with-httpclient/#how-to-parse-a-json-document-from-an-http-response

"Unfortunately, by using the underlying Stream, we bypass the code that handles chunked transfer encoding, so we must switch to HTTP version 1.0."

Sniffing the traffic, the response is indeed "HTTP 1.1" and _http.getStream() returns empty while _http.getString() does not.

When I add _http.useHTTP10(true); as mentioned in the arduniojson docs before the _http.GET(), the call is "HTTP 1.0" and the manifest can be decoded. However this does disable chunked transfers.

Can _http.useHTTP10(true); be added for calls to the manifest? Alternatively one could use the _http.getString(); but this is only ok for very small jsons.

sschueller commented 1 year ago

Here is a work around for anyone wanting to use Symphony php framework to serve the updates:

In your Controller:

// remove chunked to support arduino http 1.0 
$response = (new JsonResponse(json_encode($listOfFirmwaresArray, (JSON_UNESCAPED_SLASHES)), 200, [], true));
$response->headers->remove('Transfer-Encoding');
$response->headers->set('Content-Length', strlen($response->getContent()));
return $response;