mathworks / thingspeak-arduino

ThingSpeak Communication Library for Arduino, ESP8266 and ESP32
https://thingspeak.com
438 stars 231 forks source link

Client can't handle chunked transfer encoding from api.thingspeak.com #72

Closed jessa0 closed 3 years ago

jessa0 commented 4 years ago

This seems to be a revival of #56. api.thingspeak.com seems to be returning Transfer-Encoding: chunked starting some time around April 2020, as my sensors stopped being able to readRaw() with return code ERR_BAD_RESPONSE at that time. If I enable #define PRINT_HTTP, the client prints:

Got Status of 200
ERROR: Didn't find Content-Length header

Fetching from a computer via curl:

$ curl --http1.1 -H "Accept:" -H "User-Agent: tslib-arduino/1.5.0 (ESP8266)" -v "http://api.thingspeak.com/channels/9/feeds.json?results=0"
*   Trying 54.210.227.170:80...
* TCP_NODELAY set
* Connected to api.thingspeak.com (54.210.227.170) port 80 (#0)
> GET /channels/9/feeds.json?results=0 HTTP/1.1
> Host: api.thingspeak.com
> User-Agent: tslib-arduino/1.5.0 (ESP8266)
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Date: Sat, 26 Sep 2020 17:41:49 GMT
< Content-Type: application/json; charset=utf-8
< Transfer-Encoding: chunked
< Connection: keep-alive
< Status: 200 OK
< X-Frame-Options: SAMEORIGIN
< Access-Control-Allow-Origin: *
< Access-Control-Allow-Methods: GET, POST, PUT, OPTIONS, DELETE, PATCH
< Access-Control-Allow-Headers: origin, content-type, X-Requested-With
< Access-Control-Max-Age: 1800
< ETag: W/"38323ee74894e86109190c9e8ae8dde9"
< Cache-Control: max-age=0, private, must-revalidate
< X-Request-Id: 924f3876-5c93-42d3-9d61-1a8670b69c15
< X-Runtime: 0.010977
< X-Powered-By: Phusion Passenger 4.0.57
< Server: nginx/1.9.3 + Phusion Passenger 4.0.57
< 
* Connection #0 to host api.thingspeak.com left intact
{"channel":{"id":9,"name":"my_house","description":"Netduino Plus connected to sensors around the house","latitude":"40.44","longitude":"-79.9965","field1":"Light","field2":"Outside Temperature","created_at":"2010-12-14T01:20:06Z","updated_at":"2018-07-22T04:59:08Z","last_entry_id":16606903},"feeds":[]}

The two obvious fixes are either to fix the client to support chunked transfer encoding, or to turn off chunked transfer encoding on the server.

v-c commented 3 years ago

Chunked transfer has been turned off server side. Also, confirmed that this issue does not affect v2 of the library.