GithubHelp home page GithubHelp logo

vyruz1986 / esp8266restclient Goto Github PK

View Code? Open in Web Editor NEW

This project forked from fabianofranca/esp8266restclient

0.0 0.0 0.0 36 KB

ESP8266 RESTful HTTP Request Library

License: MIT License

C++ 100.00%

esp8266restclient's People

Contributors

csquared avatar fabianofranca avatar ianmercer avatar ivankravets avatar jamesward avatar rodrigosclosa avatar

Watchers

 avatar  avatar

esp8266restclient's Issues

Chunked HTTP responses are not handled correctly

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.