Skip to content

Commit 3489cc8

Browse files
committed
Networking: don't enable HTTP compression if server doesn't support it
1 parent 28bc97b commit 3489cc8

File tree

4 files changed

+43
-28
lines changed

4 files changed

+43
-28
lines changed

src/common/networking/networking.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ typedef struct FFNetworkingState {
2525

2626
uint32_t timeout;
2727
bool ipv6;
28-
bool compression;
28+
bool compression; // if true, HTTP content compression will be enabled if supported
2929
} FFNetworkingState;
3030

3131
const char* ffNetworkingSendHttpRequest(FFNetworkingState* state, const char* host, const char* path, const char* headers);

src/common/networking/networking_linux.c

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -283,22 +283,29 @@ const char* ffNetworkingSendHttpRequest(FFNetworkingState* state, const char* ho
283283
{
284284
FF_DEBUG("Preparing to send HTTP request: host=%s, path=%s", host, path);
285285

286-
// Initialize with compression disabled by default
287-
state->compression = false;
286+
if (state->compression)
287+
{
288+
FF_DEBUG("Compression enabled, checking if zlib is available");
288289

289-
#ifdef FF_HAVE_ZLIB
290-
const char* zlibError = ffNetworkingLoadZlibLibrary();
291-
// Only enable compression if zlib library is successfully loaded
292-
if (zlibError == NULL)
290+
#ifdef FF_HAVE_ZLIB
291+
const char* zlibError = ffNetworkingLoadZlibLibrary();
292+
// Only enable compression if zlib library is successfully loaded
293+
if (zlibError == NULL)
294+
{
295+
FF_DEBUG("Successfully loaded zlib library, compression enabled");
296+
} else {
297+
FF_DEBUG("Failed to load zlib library, compression disabled: %s", zlibError);
298+
state->compression = false;
299+
}
300+
#else
301+
FF_DEBUG("zlib not supported at build time, compression disabled");
302+
state->compression = false;
303+
#endif
304+
}
305+
else
293306
{
294-
state->compression = true;
295-
FF_DEBUG("Successfully loaded zlib library, compression enabled");
296-
} else {
297-
FF_DEBUG("Failed to load zlib library, compression disabled: %s", zlibError);
307+
FF_DEBUG("Compression disabled");
298308
}
299-
#else
300-
FF_DEBUG("zlib not supported at build time, compression disabled");
301-
#endif
302309

303310
const char* initResult = initNetworkingState(state, host, path, headers);
304311
if (initResult != NULL) {

src/common/networking/networking_windows.c

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,22 +49,27 @@ const char* ffNetworkingSendHttpRequest(FFNetworkingState* state, const char* ho
4949
{
5050
FF_DEBUG("Preparing to send HTTP request: host=%s, path=%s", host, path);
5151

52-
// Initialize with compression disabled by default
53-
state->compression = false;
54-
55-
#ifdef FF_HAVE_ZLIB
56-
const char* zlibError = ffNetworkingLoadZlibLibrary();
57-
// Only enable compression if zlib library is successfully loaded
58-
if (zlibError == NULL)
52+
if (state->compression)
5953
{
60-
state->compression = true;
61-
FF_DEBUG("Successfully loaded zlib library, compression enabled");
62-
} else {
63-
FF_DEBUG("Failed to load zlib library, compression disabled: %s", zlibError);
54+
#ifdef FF_HAVE_ZLIB
55+
const char* zlibError = ffNetworkingLoadZlibLibrary();
56+
// Only enable compression if zlib library is successfully loaded
57+
if (zlibError == NULL)
58+
{
59+
FF_DEBUG("Successfully loaded zlib library, compression enabled");
60+
} else {
61+
FF_DEBUG("Failed to load zlib library, compression disabled: %s", zlibError);
62+
state->compression = false;
63+
}
64+
#else
65+
FF_DEBUG("zlib not supported at build time, compression disabled");
66+
state->compression = false;
67+
#endif
68+
}
69+
else
70+
{
71+
FF_DEBUG("Compression disabled");
6472
}
65-
#else
66-
FF_DEBUG("zlib not supported at build time, compression disabled");
67-
#endif
6873

6974
static WSADATA wsaData;
7075
if (wsaData.wVersion == 0)

src/detection/publicip/publicip.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ void ffPreparePublicIp(FFPublicIpOptions* options)
1919
state->ipv6 = options->ipv6;
2020

2121
if (options->url.length == 0)
22+
{
23+
state->compression = true;
2224
*status = ffNetworkingSendHttpRequest(state, options->ipv6 ? "v6.ipinfo.io" : "ipinfo.io", "/json", NULL);
25+
}
2326
else
2427
{
2528
FF_STRBUF_AUTO_DESTROY host = ffStrbufCreateCopy(&options->url);

0 commit comments

Comments
 (0)