@@ -76,8 +76,10 @@ OTACloudProcessInterface::State OTADefaultCloudProcessInterface::startOTA() {
7676 return HttpResponseFail;
7777 }
7878
79+ context->contentLength = http_client->contentLength ();
80+
7981 // The following call is required to save the header value , keep it
80- if (http_client ->contentLength () == HttpClient::kNoContentLengthHeader ) {
82+ if (context ->contentLength == HttpClient::kNoContentLengthHeader ) {
8183 DEBUG_VERBOSE (" OTA ERROR: the response header doesn't contain \" ContentLength\" field" );
8284 return HttpHeaderErrorFail;
8385 }
@@ -184,7 +186,6 @@ void OTADefaultCloudProcessInterface::parseOta(uint8_t* buffer, size_t bufLen) {
184186 break ;
185187 }
186188 case OtaDownloadFile: {
187- const uint32_t contentLength = http_client->contentLength ();
188189 const uint32_t dataLeft = bufLen - (cursor-buffer);
189190 context->decoder .decompress (cursor, dataLeft); // TODO verify return value
190191
@@ -198,18 +199,18 @@ void OTADefaultCloudProcessInterface::parseOta(uint8_t* buffer, size_t bufLen) {
198199 context->downloadedSize += dataLeft;
199200
200201 if ((millis () - context->lastReportTime ) > 10000 ) { // Report the download progress each X millisecond
201- DEBUG_VERBOSE (" OTA Download Progress %d/%d" , context->downloadedSize , contentLength);
202+ DEBUG_VERBOSE (" OTA Download Progress %d/%d" , context->downloadedSize , context-> contentLength );
202203
203204 reportStatus (context->downloadedSize );
204205 context->lastReportTime = millis ();
205206 }
206207
207208 // TODO there should be no more bytes available when the download is completed
208- if (context->downloadedSize == contentLength) {
209+ if (context->downloadedSize == context-> contentLength ) {
209210 context->downloadState = OtaDownloadCompleted;
210211 }
211212
212- if (context->downloadedSize > contentLength) {
213+ if (context->downloadedSize > context-> contentLength ) {
213214 context->downloadState = OtaDownloadError;
214215 }
215216 // TODO fail if we exceed a timeout? and available is 0 (client is broken)
@@ -250,6 +251,7 @@ OTADefaultCloudProcessInterface::Context::Context(
250251 , headerCopiedBytes(0 )
251252 , downloadedSize(0 )
252253 , lastReportTime(0 )
254+ , contentLength(0 )
253255 , writeError(false )
254256 , decoder(putc) { }
255257
0 commit comments