vyruz1986 / esp8266restclient Goto Github PK
View Code? Open in Web Editor NEWThis project forked from fabianofranca/esp8266restclient
ESP8266 RESTful HTTP Request Library
License: MIT License
This project forked from fabianofranca/esp8266restclient
ESP8266 RESTful HTTP Request Library
License: MIT License
I believe I found an issue with chunked HTTP responses in this library.
I was trying to use this library with the Adafruit IO REST API and ran into the following problem:
The code I used to make the request was as follows:
RestClient RClient("io.adafruit.com", 443);
RClient.setSecureConnection(true);
RClient.setFingerprint("26 96 1c 2a 51 07 fd 15 80 96 93 ae f7 32 ce b9 0d 01 55 c4");
String strResponseBody;
strFeedName = "/api/feeds/fueltank-ullage/data/last";
RClient.setHeader("x-aio-key: ------------blanked------------");
int iResponseCode = RClient.get(strFeedName.c_str(), &strResponseBody);
The API is suppose to return JSON, but the strResponseBody string contained invalid JSON:
148
{
"id":1604311600,
"value":"1248",
"position":null,
"lat":null,
"lon":null,
"ele":null,
"feed_id":622037,
"group_id":null,
"expiration":null,
"completed_at":"2016-11-12T10:56:52.521Z",
"created_at":"2016-11-12T10:50:15.149Z",
"updated_at":"2016-11-12T10:56:52.521Z",
"created_epoch":1478947815.14934
}
0
As you can see there is 148
before and 0
behind the JSON response.
When I enabled debug logs of the library I could see the headers which were being sent:
Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Connection: close
Status: 200 OK
X-AIO-Worker: ip-172-31-58-198
Cache-Control: max-age=0, private, must-revalidate
X-XSS-Protection: 1; mode=block
X-Request-Id: 52ef11df-a197-4458-95f9-de6a80435d2a
ETag: W/"8807bff44e129c375b963f473cbfa1a9"
X-Frame-Options: SAMEORIGIN
X-Runtime: 0.025588
X-Content-Type-Options: nosniff
Date: Sat, 12 Nov 2016 10:56:52 GMT
X-Powered-By: Phusion Passenger 5.0.28
Server: nginx + Phusion Passenger 5.0.28
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
Access-Control-Allow-Methods: GET
Access-Control-Allow-Headers: DNT,X-AIO-Key,Accept,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type
The Transfer-Encoding: chunked
peaked my interest, after looking this up I found a nice description of this header on the mozilla developer pages. As you can see the 148 and 0 found in the response are indicators of HTTP chunk sizes.
The library does not seem to handle these correctly since obviously the should not be part of the body that is set by the .get()
function.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.