@@ -264,7 +264,7 @@ void HTTPClient::setAuthorization(const char * auth) {
264
264
265
265
/* *
266
266
* set the timeout for the TCP connection
267
- * @param timeout unsigned int
267
+ * @param timeout unsigned int
268
268
*/
269
269
void HTTPClient::setTimeout (uint16_t timeout) {
270
270
_tcpTimeout = timeout;
@@ -273,14 +273,12 @@ void HTTPClient::setTimeout(uint16_t timeout) {
273
273
}
274
274
}
275
275
276
-
277
-
278
276
/* *
279
277
* use HTTP1.0
280
278
* @param timeout
281
279
*/
282
280
void HTTPClient::useHTTP10 (bool useHTTP10) {
283
- _useHTTP10 = useHTTP10;
281
+ _useHTTP10 = useHTTP10;
284
282
}
285
283
286
284
/* *
@@ -392,7 +390,6 @@ int HTTPClient::sendRequest(const char * type, Stream * stream, size_t size) {
392
390
// create buffer for read
393
391
uint8_t * buff = (uint8_t *) malloc (buff_size);
394
392
395
-
396
393
if (buff) {
397
394
// read all data from stream and send it to server
398
395
while (connected () && (stream->available () > -1 ) && (len > 0 || len == -1 )) {
@@ -471,8 +468,7 @@ int HTTPClient::sendRequest(const char * type, Stream * stream, size_t size) {
471
468
free (buff);
472
469
473
470
if (size && (int ) size != bytesWritten) {
474
- DEBUG_HTTPCLIENT (" [HTTP-Client][sendRequest] Stream payload bytesWritten %d and size %d mismatch!.\n " , bytesWritten, size);
475
- DEBUG_HTTPCLIENT (" [HTTP-Client][sendRequest] ERROR SEND PAYLOAD FAILED!" );
471
+ DEBUG_HTTPCLIENT (" [HTTP-Client][sendRequest] Stream payload bytesWritten %d and size %d mismatch!.\n " , bytesWritten, size); DEBUG_HTTPCLIENT (" [HTTP-Client][sendRequest] ERROR SEND PAYLOAD FAILED!" );
476
472
return returnError (HTTPC_ERROR_SEND_PAYLOAD_FAILED);
477
473
} else {
478
474
DEBUG_HTTPCLIENT (" [HTTP-Client][sendRequest] Stream payload written: %d\n " , bytesWritten);
@@ -829,17 +825,21 @@ int HTTPClient::handleHeaderResponse() {
829
825
if (!connected ()) {
830
826
return HTTPC_ERROR_NOT_CONNECTED;
831
827
}
828
+
832
829
String transferEncoding;
833
830
_returnCode = -1 ;
834
831
_size = -1 ;
835
832
_transferEncoding = HTTPC_TE_IDENTITY;
833
+ unsigned long lastDataTime = millis ();
836
834
837
835
while (connected ()) {
838
836
size_t len = _tcp->available ();
839
837
if (len > 0 ) {
840
838
String headerLine = _tcp->readStringUntil (' \n ' );
841
839
headerLine.trim (); // remove \r
842
840
841
+ lastDataTime = millis ();
842
+
843
843
DEBUG_HTTPCLIENT (" [HTTP-Client][handleHeaderResponse] RX: '%s'\n " , headerLine.c_str ());
844
844
845
845
if (headerLine.startsWith (" HTTP/1." )) {
@@ -895,15 +895,16 @@ int HTTPClient::handleHeaderResponse() {
895
895
}
896
896
897
897
} else {
898
+ if ((millis () - lastDataTime) > _tcpTimeout) {
899
+ return HTTPC_ERROR_READ_TIMEOUT;
900
+ }
898
901
delay (0 );
899
902
}
900
903
}
901
904
902
905
return HTTPC_ERROR_CONNECTION_LOST;
903
906
}
904
907
905
-
906
-
907
908
/* *
908
909
* write one Data Block to Stream
909
910
* @param stream Stream *
0 commit comments