From 05bd8a35817d597232c9d0982c16dc6953ae14f7 Mon Sep 17 00:00:00 2001 From: Florian Ludwig Date: Sat, 6 Feb 2021 16:09:43 +0100 Subject: [PATCH] treat http headers case insensitive in OTA --- src/ota.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/ota.cpp b/src/ota.cpp index 6b94a193..bf4a41e0 100644 --- a/src/ota.cpp +++ b/src/ota.cpp @@ -189,6 +189,8 @@ int do_ota_update() { while (client.available()) { String line = client.readStringUntil('\n'); + String lineLowerCase = line; + lineLowerCase.toLowerCase(); // Check if the line is end of headers by removing space symbol line.trim(); // if the the line is empty, this is the end of the headers @@ -213,8 +215,8 @@ int do_ota_update() { } // Extracting new redirect location - if (line.startsWith("Location: ")) { - String newUrl = getHeaderValue(line, "Location: "); + if (lineLowerCase.startsWith("location: ")) { + String newUrl = getHeaderValue(line, "location: "); ESP_LOGI(TAG, "Got new url: %s", newUrl.c_str()); newUrl.remove(0, newUrl.indexOf("//") + 2); currentHost = newUrl.substring(0, newUrl.indexOf('/')); @@ -224,14 +226,14 @@ int do_ota_update() { } // Checking headers - if (line.startsWith("Content-Length: ")) { + if (lineLowerCase.startsWith("content-length: ")) { contentLength = - atoi((getHeaderValue(line, "Content-Length: ")).c_str()); + atoi((getHeaderValue(line, "content-length: ")).c_str()); ESP_LOGI(TAG, "Got %d bytes from server", contentLength); } - if (line.startsWith("Content-Type: ")) { - String contentType = getHeaderValue(line, "Content-Type: "); + if (lineLowerCase.startsWith("content-type: ")) { + String contentType = getHeaderValue(line, "content-type: "); ESP_LOGI(TAG, "Got %s payload", contentType.c_str()); if (contentType == "application/octet-stream") { isValidContentType = true;