File tree Expand file tree Collapse file tree 2 files changed +38
-1
lines changed
libraries/ESP8266httpClient/src Expand file tree Collapse file tree 2 files changed +38
-1
lines changed Original file line number Diff line number Diff line change 2525#include < Arduino.h>
2626#include < ESP8266WiFi.h>
2727#include < WiFiClientSecure.h>
28+ #include < StreamString.h>
2829
2930#include " ESP8266httpClient.h"
3031
@@ -198,6 +199,7 @@ int httpClient::getSize(void) {
198199}
199200
200201/* *
202+ * deprecated Note: this is not working with https!
201203 * returns the stram of the tcp connection
202204 * @return WiFiClient
203205 */
@@ -211,6 +213,20 @@ WiFiClient & httpClient::getStream(void) {
211213 // todo return error?
212214}
213215
216+ /* *
217+ * returns the stram of the tcp connection
218+ * @return WiFiClient *
219+ */
220+ WiFiClient * httpClient::getStreamPtr (void ) {
221+ if (connected ()) {
222+ return _tcp;
223+ }
224+
225+ DEBUG_HTTPCLIENT (" [HTTP-Client] no stream to return!?\n " );
226+ return NULL ;
227+ }
228+
229+ WiFiClient * getStreamPtr (void );
214230/* *
215231 * write all message body / payload to Stream
216232 * @param stream Stream *
@@ -265,6 +281,25 @@ int httpClient::writeToStream(Stream * stream) {
265281 return bytesWritten;
266282}
267283
284+ /* *
285+ * return all payload as String (may need lot of ram or trigger out of memmory!)
286+ * @return String
287+ */
288+ String httpClient::getString (void ) {
289+ StreamString sstring;
290+
291+ if (_size) {
292+ // try to reserve needed memmory
293+ if (!sstring.reserve ((_size + 1 ))) {
294+ DEBUG_HTTPCLIENT (" [HTTP-Client][getString] too less memory to resive as string! need: %d\n " , (_size + 1 ));
295+ return String (" --too less memory--" );
296+ }
297+ }
298+
299+ writeToStream (&sstring);
300+ return sstring;
301+ }
302+
268303/* *
269304 * adds Headder to the request
270305 * @param name
Original file line number Diff line number Diff line change @@ -75,8 +75,10 @@ class httpClient {
7575
7676 int getSize (void );
7777
78- WiFiClient & getStream (void );
78+ WiFiClient & getStream (void ) __attribute__ ((deprecated)) ;
79+ WiFiClient * getStreamPtr (void );
7980 int writeToStream (Stream * stream);
81+ String getString (void );
8082
8183 protected:
8284
You can’t perform that action at this time.
0 commit comments