* * @param http HTTPClient * * @param currentVersion const char * * @return HTTPUpdateResult */
| 191 | * @return HTTPUpdateResult |
| 192 | */ |
| 193 | HTTPUpdateResult HTTPUpdate::handleUpdate(HTTPClient &http, const String ¤tVersion, 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 *); |
nothing calls this directly
no test coverage detected