Always detect closed connection in OTA HTTP response
@@ -473,6 +473,8 @@ static void _httpReadReadyCallback( void * pPrivateData,
OTA_GOTO_CLEANUP();
}
+ OTA_FUNCTION_CLEANUP_BEGIN();
+
/* The connection could be closed by S3 after 100 requests, so we need to check the value
* of the "Connection" filed in HTTP header to see if we need to reconnect. */
memset( connectionValueStr, 0, sizeof( connectionValueStr ) );
@@ -482,22 +484,21 @@ static void _httpReadReadyCallback( void * pPrivateData,
connectionValueStr,
sizeof( connectionValueStr ) );
- /* Exit if there is any other error besides not found when parsing the http header. */
+ /* Check if there is any other error besides not found when parsing the http header. */
if( ( httpsStatus != IOT_HTTPS_OK ) && ( httpsStatus != IOT_HTTPS_NOT_FOUND ) )
{
IotLogError( "Failed to read header Connection. Error code: %d.", httpsStatus );
_httpDownloader.err = OTA_HTTP_ERR_GENERIC;
- OTA_GOTO_CLEANUP();
}
-
+ else
+ {
/* Check if the server returns a response with connection field set to "close". */
if( strncmp( "close", connectionValueStr, sizeof( "close" ) ) == 0 )
{
IotLogInfo( "Connection has been closed by the HTTP server, reconnecting to the server..." );
_httpReconnect();
}
-
- OTA_FUNCTION_CLEANUP_BEGIN();
+ }
/* Cancel receiving the response in case of error, _httpErrorCallback will be invoked next.
* If the HTTP error is IOT_HTTPS_NETWORK_ERROR, the connection will then be closed by the HTTP
