@@ -53,6 +53,7 @@ enum class rp2040OTAError : int
5353 ServerConnectError = RP2040_OTA_ERROR_BASE - 10 ,
5454 HttpHeaderError = RP2040_OTA_ERROR_BASE - 11 ,
5555 HttpDataError = RP2040_OTA_ERROR_BASE - 12 ,
56+ HttpResponse = RP2040_OTA_ERROR_BASE - 14 ,
5657 ErrorOpenUpdateFile = RP2040_OTA_ERROR_BASE - 19 ,
5758 ErrorWriteUpdateFile = RP2040_OTA_ERROR_BASE - 20 ,
5859 ErrorReformat = RP2040_OTA_ERROR_BASE - 21 ,
@@ -207,6 +208,26 @@ int rp2040_connect_onOTARequest(char const * ota_url)
207208 return static_cast <int >(rp2040OTAError::HttpHeaderError);
208209 }
209210
211+ /* Check HTTP response status code */
212+ char const * http_response_ptr = strstr (http_header.c_str (), " HTTP/1.1" );
213+ if (!http_response_ptr)
214+ {
215+ DEBUG_ERROR (" %s: Failure to extract http response from header" , __FUNCTION__);
216+ return static_cast <int >(rp2040OTAError::ErrorParseHttpHeader);
217+ }
218+ /* Find start of numerical value. */
219+ char * ptr = const_cast <char *>(http_response_ptr);
220+ for (ptr += strlen (" HTTP/1.1" ); (*ptr != ' \0 ' ) && !isDigit (*ptr); ptr++) { }
221+ /* Extract numerical value. */
222+ String http_response_str;
223+ for (; isDigit (*ptr); ptr++) http_response_str += *ptr;
224+ int const http_response = atoi (http_response_str.c_str ());
225+
226+ if (http_response != 200 ) {
227+ DEBUG_ERROR (" %s: HTTP response status code = %d" , __FUNCTION__, http_response);
228+ return static_cast <int >(rp2040OTAError::HttpResponse);
229+ }
230+
210231 /* Extract concent length from HTTP header. A typical entry looks like
211232 * "Content-Length: 123456"
212233 */
@@ -218,7 +239,7 @@ int rp2040_connect_onOTARequest(char const * ota_url)
218239 return static_cast <int >(rp2040OTAError::ErrorParseHttpHeader);
219240 }
220241 /* Find start of numerical value. */
221- char * ptr = const_cast <char *>(content_length_ptr);
242+ ptr = const_cast <char *>(content_length_ptr);
222243 for (; (*ptr != ' \0 ' ) && !isDigit (*ptr); ptr++) { }
223244 /* Extract numerical value. */
224245 String content_length_str;
0 commit comments