Networking: don't enable HTTP compression if server doesn't support it

This commit is contained in:
Carter Li
2025-03-18 09:56:35 +08:00
parent 28bc97b92b
commit 3489cc8fe8
4 changed files with 44 additions and 29 deletions
+1 -1
View File
@@ -25,7 +25,7 @@ typedef struct FFNetworkingState {
uint32_t timeout;
bool ipv6;
bool compression;
bool compression; // if true, HTTP content compression will be enabled if supported
} FFNetworkingState;
const char* ffNetworkingSendHttpRequest(FFNetworkingState* state, const char* host, const char* path, const char* headers);
+21 -14
View File
@@ -283,22 +283,29 @@ const char* ffNetworkingSendHttpRequest(FFNetworkingState* state, const char* ho
{
FF_DEBUG("Preparing to send HTTP request: host=%s, path=%s", host, path);
// Initialize with compression disabled by default
state->compression = false;
#ifdef FF_HAVE_ZLIB
const char* zlibError = ffNetworkingLoadZlibLibrary();
// Only enable compression if zlib library is successfully loaded
if (zlibError == NULL)
if (state->compression)
{
state->compression = true;
FF_DEBUG("Successfully loaded zlib library, compression enabled");
} else {
FF_DEBUG("Failed to load zlib library, compression disabled: %s", zlibError);
FF_DEBUG("Compression enabled, checking if zlib is available");
#ifdef FF_HAVE_ZLIB
const char* zlibError = ffNetworkingLoadZlibLibrary();
// Only enable compression if zlib library is successfully loaded
if (zlibError == NULL)
{
FF_DEBUG("Successfully loaded zlib library, compression enabled");
} else {
FF_DEBUG("Failed to load zlib library, compression disabled: %s", zlibError);
state->compression = false;
}
#else
FF_DEBUG("zlib not supported at build time, compression disabled");
state->compression = false;
#endif
}
else
{
FF_DEBUG("Compression disabled");
}
#else
FF_DEBUG("zlib not supported at build time, compression disabled");
#endif
const char* initResult = initNetworkingState(state, host, path, headers);
if (initResult != NULL) {
+19 -14
View File
@@ -49,22 +49,27 @@ const char* ffNetworkingSendHttpRequest(FFNetworkingState* state, const char* ho
{
FF_DEBUG("Preparing to send HTTP request: host=%s, path=%s", host, path);
// Initialize with compression disabled by default
state->compression = false;
#ifdef FF_HAVE_ZLIB
const char* zlibError = ffNetworkingLoadZlibLibrary();
// Only enable compression if zlib library is successfully loaded
if (zlibError == NULL)
if (state->compression)
{
state->compression = true;
FF_DEBUG("Successfully loaded zlib library, compression enabled");
} else {
FF_DEBUG("Failed to load zlib library, compression disabled: %s", zlibError);
#ifdef FF_HAVE_ZLIB
const char* zlibError = ffNetworkingLoadZlibLibrary();
// Only enable compression if zlib library is successfully loaded
if (zlibError == NULL)
{
FF_DEBUG("Successfully loaded zlib library, compression enabled");
} else {
FF_DEBUG("Failed to load zlib library, compression disabled: %s", zlibError);
state->compression = false;
}
#else
FF_DEBUG("zlib not supported at build time, compression disabled");
state->compression = false;
#endif
}
else
{
FF_DEBUG("Compression disabled");
}
#else
FF_DEBUG("zlib not supported at build time, compression disabled");
#endif
static WSADATA wsaData;
if (wsaData.wVersion == 0)
+3
View File
@@ -19,7 +19,10 @@ void ffPreparePublicIp(FFPublicIpOptions* options)
state->ipv6 = options->ipv6;
if (options->url.length == 0)
{
state->compression = true;
*status = ffNetworkingSendHttpRequest(state, options->ipv6 ? "v6.ipinfo.io" : "ipinfo.io", "/json", NULL);
}
else
{
FF_STRBUF_AUTO_DESTROY host = ffStrbufCreateCopy(&options->url);