@@ -76,8 +76,10 @@ OTACloudProcessInterface::State OTADefaultCloudProcessInterface::startOTA() {
76
76
return HttpResponseFail;
77
77
}
78
78
79
+ context->contentLength = http_client->contentLength ();
80
+
79
81
// 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 ) {
81
83
DEBUG_VERBOSE (" OTA ERROR: the response header doesn't contain \" ContentLength\" field" );
82
84
return HttpHeaderErrorFail;
83
85
}
@@ -184,7 +186,6 @@ void OTADefaultCloudProcessInterface::parseOta(uint8_t* buffer, size_t bufLen) {
184
186
break ;
185
187
}
186
188
case OtaDownloadFile: {
187
- const uint32_t contentLength = http_client->contentLength ();
188
189
const uint32_t dataLeft = bufLen - (cursor-buffer);
189
190
context->decoder .decompress (cursor, dataLeft); // TODO verify return value
190
191
@@ -198,18 +199,18 @@ void OTADefaultCloudProcessInterface::parseOta(uint8_t* buffer, size_t bufLen) {
198
199
context->downloadedSize += dataLeft;
199
200
200
201
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 );
202
203
203
204
reportStatus (context->downloadedSize );
204
205
context->lastReportTime = millis ();
205
206
}
206
207
207
208
// TODO there should be no more bytes available when the download is completed
208
- if (context->downloadedSize == contentLength) {
209
+ if (context->downloadedSize == context-> contentLength ) {
209
210
context->downloadState = OtaDownloadCompleted;
210
211
}
211
212
212
- if (context->downloadedSize > contentLength) {
213
+ if (context->downloadedSize > context-> contentLength ) {
213
214
context->downloadState = OtaDownloadError;
214
215
}
215
216
// TODO fail if we exceed a timeout? and available is 0 (client is broken)
@@ -250,6 +251,7 @@ OTADefaultCloudProcessInterface::Context::Context(
250
251
, headerCopiedBytes(0 )
251
252
, downloadedSize(0 )
252
253
, lastReportTime(0 )
254
+ , contentLength(0 )
253
255
, writeError(false )
254
256
, decoder(putc) { }
255
257
0 commit comments