Networking: ensure server returns 200 OK

This commit is contained in:
李通洲
2022-09-30 17:43:23 +08:00
parent 265254ddf7
commit 9418138892
4 changed files with 13 additions and 11 deletions
+3 -3
View File
@@ -47,10 +47,10 @@ void ffPrintPublicIp(FFinstance* instance)
FFstrbuf result;
ffStrbufInitA(&result, 4096);
ffNetworkingRecvHttpResponse(sockfd, &result);
ffStrbufSubstrAfterFirstS(&result, "\r\n\r\n");
bool success = ffNetworkingRecvHttpResponse(sockfd, &result);
if(success) ffStrbufSubstrAfterFirstS(&result, "\r\n\r\n");
if(result.length == 0)
if(!success || result.length == 0)
{
ffPrintError(instance, FF_PUBLICIP_MODULE_NAME, 0, &instance->config.publicIP, "Failed to receive the server response");
ffStrbufDestroy(&result);
+3 -3
View File
@@ -29,10 +29,10 @@ void ffPrintWeather(FFinstance* instance)
FFstrbuf result;
ffStrbufInitA(&result, 4096);
ffNetworkingRecvHttpResponse(sockfd, &result);
ffStrbufSubstrAfterFirstS(&result, "\r\n\r\n");
bool success = ffNetworkingRecvHttpResponse(sockfd, &result);
if (success) ffStrbufSubstrAfterFirstS(&result, "\r\n\r\n");
if(result.length == 0)
if(!success || result.length == 0)
{
ffPrintError(instance, FF_WEATHER_MODULE_NAME, 0, &instance->config.weather, "Failed to receive the server response");
ffStrbufDestroy(&result);