@@ -80,11 +80,15 @@ void httpClient::begin(String host, uint16_t port, String url, bool https, Strin
80
80
* called after the payload is handeld
81
81
*/
82
82
void httpClient::end (void ) {
83
- if ((!_reuse || !_canReuse) && connected ()) {
84
- DEBUG_HTTPCLIENT (" [HTTP-Client][end] tcp stop \n " );
85
- _tcp->stop ();
83
+ if (connected ()) {
84
+ if (_reuse && _canReuse) {
85
+ DEBUG_HTTPCLIENT (" [HTTP-Client][end] tcp keep open for reuse\n " );
86
+ } else {
87
+ DEBUG_HTTPCLIENT (" [HTTP-Client][end] tcp stop\n " );
88
+ _tcp->stop ();
89
+ }
86
90
} else {
87
- DEBUG_HTTPCLIENT (" [HTTP-Client][end] tcp keep open for reuse \n " );
91
+ DEBUG_HTTPCLIENT (" [HTTP-Client][end] tcp is closed \n " );
88
92
}
89
93
}
90
94
@@ -189,12 +193,16 @@ WiFiClient & httpClient::getStream(void) {
189
193
/* *
190
194
* write all message body / payload to Stream
191
195
* @param stream Stream *
192
- * @return bytes written
196
+ * @return bytes written ( negative values are error codes )
193
197
*/
194
198
int httpClient::writeToStream (Stream * stream) {
195
199
196
200
if (!stream) {
197
- return -1 ;
201
+ return HTTPC_ERROR_NO_STREAM;
202
+ }
203
+
204
+ if (!connected ()) {
205
+ return HTTPC_ERROR_NOT_CONNECTED;
198
206
}
199
207
200
208
// get lenght of document (is -1 when Server sends no Content-Length header)
@@ -219,14 +227,17 @@ int httpClient::writeToStream(Stream * stream) {
219
227
if (len > 0 ) {
220
228
len -= c;
221
229
}
230
+
231
+ delay (0 );
232
+ } else {
233
+ delay (1 );
222
234
}
223
- delay (1 );
224
235
}
225
236
226
- DEBUG_HTTPCLIENT (" [HTTP-Client] connection closed or file end.\n " );
237
+ DEBUG_HTTPCLIENT (" [HTTP-Client][writeToStream] connection closed or file end (written: %d) .\n " , bytesWritten );
227
238
228
239
if (_size && _size != bytesWritten) {
229
- DEBUG_HTTPCLIENT (" [HTTP-Client] bytesWritten %d and size %d missmatch!.\n " , bytesWritten, _size);
240
+ DEBUG_HTTPCLIENT (" [HTTP-Client][writeToStream] bytesWritten %d and size %d missmatch!.\n " , bytesWritten, _size);
230
241
}
231
242
232
243
end ();
0 commit comments