@@ -53,6 +53,7 @@ enum class rp2040OTAError : int
53
53
ServerConnectError = RP2040_OTA_ERROR_BASE - 10 ,
54
54
HttpHeaderError = RP2040_OTA_ERROR_BASE - 11 ,
55
55
HttpDataError = RP2040_OTA_ERROR_BASE - 12 ,
56
+ HttpResponse = RP2040_OTA_ERROR_BASE - 14 ,
56
57
ErrorOpenUpdateFile = RP2040_OTA_ERROR_BASE - 19 ,
57
58
ErrorWriteUpdateFile = RP2040_OTA_ERROR_BASE - 20 ,
58
59
ErrorReformat = RP2040_OTA_ERROR_BASE - 21 ,
@@ -207,6 +208,26 @@ int rp2040_connect_onOTARequest(char const * ota_url)
207
208
return static_cast <int >(rp2040OTAError::HttpHeaderError);
208
209
}
209
210
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
+
210
231
/* Extract concent length from HTTP header. A typical entry looks like
211
232
* "Content-Length: 123456"
212
233
*/
@@ -218,7 +239,7 @@ int rp2040_connect_onOTARequest(char const * ota_url)
218
239
return static_cast <int >(rp2040OTAError::ErrorParseHttpHeader);
219
240
}
220
241
/* Find start of numerical value. */
221
- char * ptr = const_cast <char *>(content_length_ptr);
242
+ ptr = const_cast <char *>(content_length_ptr);
222
243
for (; (*ptr != ' \0 ' ) && !isDigit (*ptr); ptr++) { }
223
244
/* Extract numerical value. */
224
245
String content_length_str;
0 commit comments