diff --git a/libraries/ESP8266httpClient/src/ESP8266httpClient.cpp b/libraries/ESP8266httpClient/src/ESP8266httpClient.cpp index 1e27af2a3..7e3fd6fec 100644 --- a/libraries/ESP8266httpClient/src/ESP8266httpClient.cpp +++ b/libraries/ESP8266httpClient/src/ESP8266httpClient.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include "ESP8266httpClient.h" @@ -198,6 +199,7 @@ int httpClient::getSize(void) { } /** + * deprecated Note: this is not working with https! * returns the stram of the tcp connection * @return WiFiClient */ @@ -211,6 +213,20 @@ WiFiClient & httpClient::getStream(void) { // todo return error? } +/** + * returns the stram of the tcp connection + * @return WiFiClient * + */ +WiFiClient * httpClient::getStreamPtr(void) { + if(connected()) { + return _tcp; + } + + DEBUG_HTTPCLIENT("[HTTP-Client] no stream to return!?\n"); + return NULL; +} + +WiFiClient * getStreamPtr(void); /** * write all message body / payload to Stream * @param stream Stream * @@ -265,6 +281,25 @@ int httpClient::writeToStream(Stream * stream) { return bytesWritten; } +/** + * return all payload as String (may need lot of ram or trigger out of memmory!) + * @return String + */ +String httpClient::getString(void) { + StreamString sstring; + + if(_size) { + // try to reserve needed memmory + if(!sstring.reserve((_size + 1))) { + DEBUG_HTTPCLIENT("[HTTP-Client][getString] too less memory to resive as string! need: %d\n", (_size + 1)); + return String("--too less memory--"); + } + } + + writeToStream(&sstring); + return sstring; +} + /** * adds Headder to the request * @param name diff --git a/libraries/ESP8266httpClient/src/ESP8266httpClient.h b/libraries/ESP8266httpClient/src/ESP8266httpClient.h index ddc0cea35..9d69f3ed3 100644 --- a/libraries/ESP8266httpClient/src/ESP8266httpClient.h +++ b/libraries/ESP8266httpClient/src/ESP8266httpClient.h @@ -75,8 +75,10 @@ class httpClient { int getSize(void); - WiFiClient & getStream(void); + WiFiClient & getStream(void) __attribute__ ((deprecated)) ; + WiFiClient * getStreamPtr(void); int writeToStream(Stream * stream); + String getString(void); protected: