MCPcopy Create free account
hub / github.com/Heltec-Aaron-Lee/WiFi_Kit_series / handleUpdate

Method handleUpdate

libraries/HTTPUpdate/src/HTTPUpdate.cpp:193–433  ·  view source on GitHub ↗

* * @param http HTTPClient * * @param currentVersion const char * * @return HTTPUpdateResult */

Source from the content-addressed store, hash-verified

191 * @return HTTPUpdateResult
192 */
193HTTPUpdateResult HTTPUpdate::handleUpdate(HTTPClient &http, const String &currentVersion, uint8_t type, HTTPUpdateRequestCB requestCB) {
194
195 HTTPUpdateResult ret = HTTP_UPDATE_FAILED;
196
197 // use HTTP/1.0 for update since the update handler not support any transfer Encoding
198 http.useHTTP10(true);
199 http.setTimeout(_httpClientTimeout);
200 http.setFollowRedirects(_followRedirects);
201 http.setUserAgent("ESP32-http-Update");
202 http.addHeader("Cache-Control", "no-cache");
203 http.addHeader("x-ESP32-BASE-MAC", Network.macAddress());
204#if SOC_WIFI_SUPPORTED
205 http.addHeader("x-ESP32-STA-MAC", WiFi.macAddress());
206 http.addHeader("x-ESP32-AP-MAC", WiFi.softAPmacAddress());
207#endif
208 http.addHeader("x-ESP32-free-space", String(ESP.getFreeSketchSpace()));
209 http.addHeader("x-ESP32-sketch-size", String(ESP.getSketchSize()));
210 String sketchMD5 = ESP.getSketchMD5();
211 if (sketchMD5.length() != 0) {
212 http.addHeader("x-ESP32-sketch-md5", sketchMD5);
213 }
214 // Add also a SHA256
215 String sketchSHA256 = getSketchSHA256();
216 if (sketchSHA256.length() != 0) {
217 http.addHeader("x-ESP32-sketch-sha256", sketchSHA256);
218 }
219 http.addHeader("x-ESP32-chip-size", String(ESP.getFlashChipSize()));
220 http.addHeader("x-ESP32-sdk-version", ESP.getSdkVersion());
221
222 if (type == U_SPIFFS) {
223 http.addHeader("x-ESP32-mode", "spiffs");
224 } else if (type == U_FATFS) {
225 http.addHeader("x-ESP32-mode", "fatfs");
226 } else if (type == U_LITTLEFS) {
227 http.addHeader("x-ESP32-mode", "littlefs");
228 } else if (type == U_FLASHFS) {
229 http.addHeader("x-ESP32-mode", "flashfs");
230 } else {
231 http.addHeader("x-ESP32-mode", "sketch");
232 }
233
234 if (currentVersion && currentVersion[0] != 0x00) {
235 http.addHeader("x-ESP32-version", currentVersion);
236 }
237 if (requestCB) {
238 requestCB(&http);
239 }
240
241 if (!_user.isEmpty() && !_password.isEmpty()) {
242 http.setAuthorization(_user.c_str(), _password.c_str());
243 }
244
245 if (!_auth.isEmpty()) {
246 http.setAuthorization(_auth.c_str());
247 }
248
249 const char *headerkeys[] = {"x-MD5"};
250 size_t headerkeyssize = sizeof(headerkeys) / sizeof(char *);

Callers

nothing calls this directly

Calls 15

StringClass · 0.85
getSketchSHA256Function · 0.85
delayFunction · 0.85
useHTTP10Method · 0.80
setUserAgentMethod · 0.80
addHeaderMethod · 0.80
softAPmacAddressMethod · 0.80
getFreeSketchSpaceMethod · 0.80
getSketchSizeMethod · 0.80
getSketchMD5Method · 0.80
getFlashChipSizeMethod · 0.80
getSdkVersionMethod · 0.80

Tested by

no test coverage detected