diff --git a/app/http/httpclient.c b/app/http/httpclient.c index 0ac8bf4f..094c5ece 100644 --- a/app/http/httpclient.c +++ b/app/http/httpclient.c @@ -451,20 +451,33 @@ static void ICACHE_FLASH_ATTR http_timeout_callback( void *arg ) struct espconn * conn = (struct espconn *) arg; if ( conn == NULL ) { + HTTPCLIENT_DEBUG( "Connection is NULL" ); return; } if ( conn->reverse == NULL ) { + HTTPCLIENT_DEBUG( "Connection request data (reverse) is NULL" ); return; } request_args_t * req = (request_args_t *) conn->reverse; + HTTPCLIENT_DEBUG( "Calling disconnect" ); /* Call disconnect */ + sint8 result; #ifdef CLIENT_SSL_ENABLE if ( req->secure ) - espconn_secure_disconnect( conn ); + result = espconn_secure_disconnect( conn ); else #endif - espconn_disconnect( conn ); + result = espconn_disconnect( conn ); + + if (result == ESPCONN_OK || result == ESPCONN_INPROGRESS) + return; + else + { + /* not connected; execute the callback ourselves. */ + HTTPCLIENT_DEBUG( "manually Calling disconnect callback due to error %d", result ); + http_disconnect_callback( arg ); + } } diff --git a/docs/en/modules/http.md b/docs/en/modules/http.md index 6ead9903..8e5d4626 100644 --- a/docs/en/modules/http.md +++ b/docs/en/modules/http.md @@ -33,7 +33,7 @@ Executes a HTTP DELETE request. Note that concurrent requests are not supported. - `url` The URL to fetch, including the `http://` or `https://` prefix - `headers` Optional additional headers to append, *including \r\n*; may be `nil` - `body` The body to post; must already be encoded in the appropriate format, but may be empty -- `callback` The callback function to be invoked when the response has been received; it is invoked with the arguments `status_code`, `body` and `headers` +- `callback` The callback function to be invoked when the response has been received or an error occurred; it is invoked with the arguments `status_code`, `body` and `headers`. In case of an error `status_code` is set to -1. #### Returns `nil` @@ -62,7 +62,7 @@ Executes a HTTP GET request. Note that concurrent requests are not supported. #### Parameters - `url` The URL to fetch, including the `http://` or `https://` prefix - `headers` Optional additional headers to append, *including \r\n*; may be `nil` -- `callback` The callback function to be invoked when the response has been received; it is invoked with the arguments `status_code`, `body` and `headers` +- `callback` The callback function to be invoked when the response has been received or an error occurred; it is invoked with the arguments `status_code`, `body` and `headers`. In case of an error `status_code` is set to -1 #### Returns `nil` @@ -89,7 +89,7 @@ Executes a HTTP POST request. Note that concurrent requests are not supported. - `url` The URL to fetch, including the `http://` or `https://` prefix - `headers` Optional additional headers to append, *including \r\n*; may be `nil` - `body` The body to post; must already be encoded in the appropriate format, but may be empty -- `callback` The callback function to be invoked when the response has been received; it is invoked with the arguments `status_code`, `body` and `headers` +- `callback` The callback function to be invoked when the response has been received or an error occurred; it is invoked with the arguments `status_code`, `body` and `headers`. In case of an error `status_code` is set to -1. #### Returns `nil` @@ -119,7 +119,7 @@ Executes a HTTP PUT request. Note that concurrent requests are not supported. - `url` The URL to fetch, including the `http://` or `https://` prefix - `headers` Optional additional headers to append, *including \r\n*; may be `nil` - `body` The body to post; must already be encoded in the appropriate format, but may be empty -- `callback` The callback function to be invoked when the response has been received; it is invoked with the arguments `status_code`, `body` and `headers` +- `callback` The callback function to be invoked when the response has been received or an error occurred; it is invoked with the arguments `status_code`, `body` and `headers`. In case of an error `status_code` is set to -1. #### Returns `nil` @@ -150,7 +150,7 @@ Execute a custom HTTP request for any HTTP method. Note that concurrent requests - `method` The HTTP method to use, e.g. "GET", "HEAD", "OPTIONS" etc - `headers` Optional additional headers to append, *including \r\n*; may be `nil` - `body` The body to post; must already be encoded in the appropriate format, but may be empty -- `callback` The callback function to be invoked when the response has been received; it is invoked with the arguments `status_code`, `body` and `headers` +- `callback` The callback function to be invoked when the response has been received or an error occurred; it is invoked with the arguments `status_code`, `body` and `headers`. In case of an error `status_code` is set to -1. #### Returns `nil`