Skip to content

Commit 3791b96

Browse files
committed
[net] fix downloads no longer working after the recent GitHub server update
* GitHub appears to have updated their HTTP servers to enable gzip compression when requested. * Unfortunately, the default from Rufus was to attempt to use compression where possible (ironically in an effort to save GitHub some bandwidth), which doesn't seem to sit too well with Windows' HttpQueryInfoA(HTTP_QUERY_CONTENT_LENGTH) API, as it errors out on trying to produce the content-length *DESPITE* the field being reported by GitHub in the HTTP header. * As a result, we switch all HTTP downloads *not* to try to use compression by forcing "Accept-Encoding: identity". * Unfortunately, besides affecting the download of resources such as GRUB/Syslinux ones, it also affects the ability to look for updates, which means that NONE of the version of Rufus prior to 4.9 (outside of the Windows Store ones) will be able to find that there exists a newer version to update to... :( * Closes #2756.
1 parent e128727 commit 3791b96

File tree

2 files changed

+18
-19
lines changed

2 files changed

+18
-19
lines changed

src/net.c

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ extern BOOL is_x86_64;
5959
extern USHORT NativeMachine;
6060
static DWORD error_code, fido_len = 0;
6161
static BOOL force_update_check = FALSE;
62-
static const char* request_headers[2] = { "Accept-Encoding: none", "Accept-Encoding: gzip, deflate" };
6362
extern const char* efi_archname[ARCH_MAX];
6463

6564
#if defined(__MINGW32__)
@@ -175,7 +174,7 @@ uint64_t DownloadToFileOrBufferEx(const char* url, const char* file, const char*
175174
const char* short_name;
176175
unsigned char buf[DOWNLOAD_BUFFER_SIZE];
177176
char hostname[64], urlpath[128], strsize[32];
178-
BOOL r = FALSE, use_github_api;
177+
BOOL r = FALSE;
179178
DWORD dwSize, dwWritten, dwDownloaded;
180179
HANDLE hFile = INVALID_HANDLE_VALUE;
181180
HINTERNET hSession = NULL, hConnection = NULL, hRequest = NULL;
@@ -227,18 +226,16 @@ uint64_t DownloadToFileOrBufferEx(const char* url, const char* file, const char*
227226
goto out;
228227
}
229228

230-
// If we are querying the GitHub API, we need to enable raw content and
231-
// set 'Accept-Encoding' to 'none' to get the data length.
232-
use_github_api = (strstr(url, "api.github.com") != NULL);
233-
if (use_github_api && !HttpAddRequestHeadersA(hRequest, "Accept: application/vnd.github.v3.raw",
234-
(DWORD)-1, HTTP_ADDREQ_FLAG_ADD)) {
229+
// If we are querying the GitHub API, we need to enable raw content
230+
if (strstr(url, "api.github.com") != NULL && !HttpAddRequestHeadersA(hRequest,
231+
"Accept: application/vnd.github.v3.raw", (DWORD)-1, HTTP_ADDREQ_FLAG_ADD)) {
235232
uprintf("Unable to enable raw content from GitHub API: %s", WindowsErrorString());
236233
goto out;
237234
}
238-
if (!HttpSendRequestA(hRequest, request_headers[use_github_api ? 0 : 1], -1L, NULL, 0)) {
239-
uprintf("Unable to send request: %s", WindowsErrorString());
240-
goto out;
241-
}
235+
// Must use "Accept-Encoding: identity" to get the file size
236+
// This is needed for GitHub as the Microsoft HTTP APIs can't seem to read content-length for
237+
// compressed content from GitHub, and using "identity" disables compression.
238+
HttpSendRequestA(hRequest, "Accept-Encoding: identity", -1L, NULL, 0);
242239

243240
// Get the file size
244241
dwSize = sizeof(DownloadStatus);
@@ -643,10 +640,12 @@ static DWORD WINAPI CheckForUpdatesThread(LPVOID param)
643640
INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP | INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS |
644641
INTERNET_FLAG_NO_COOKIES | INTERNET_FLAG_NO_UI | INTERNET_FLAG_NO_CACHE_WRITE | INTERNET_FLAG_HYPERLINK |
645642
((UrlParts.nScheme == INTERNET_SCHEME_HTTPS) ? INTERNET_FLAG_SECURE : 0), (DWORD_PTR)NULL);
646-
if ((hRequest == NULL) || (!HttpSendRequestA(hRequest, request_headers[1], -1L, NULL, 0))) {
643+
if (hRequest == NULL) {
647644
uprintf("Unable to send request: %s", WindowsErrorString());
648645
goto out;
649646
}
647+
// Must use "Accept-Encoding: identity" to get the file size
648+
HttpSendRequestA(hRequest, "Accept-Encoding: identity", -1L, NULL, 0);
650649

651650
// Ensure that we get a text file
652651
dwSize = sizeof(dwStatus);
@@ -1010,8 +1009,8 @@ BOOL IsDownloadable(const char* url)
10101009
if (hRequest == NULL)
10111010
goto out;
10121011

1013-
if (!HttpSendRequestA(hRequest, request_headers[1], -1L, NULL, 0))
1014-
goto out;
1012+
// Must use "Accept-Encoding: identity" to get the file size
1013+
HttpSendRequestA(hRequest, "Accept-Encoding: identity", -1L, NULL, 0);
10151014

10161015
// Get the file size
10171016
dwSize = sizeof(DownloadStatus);

src/rufus.rc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
3333
IDD_DIALOG DIALOGEX 12, 12, 232, 326
3434
STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU
3535
EXSTYLE WS_EX_ACCEPTFILES
36-
CAPTION "Rufus 4.9.2254"
36+
CAPTION "Rufus 4.9.2255"
3737
FONT 9, "Segoe UI Symbol", 400, 0, 0x0
3838
BEGIN
3939
LTEXT "Drive Properties",IDS_DRIVE_PROPERTIES_TXT,8,6,53,12,NOT WS_GROUP
@@ -407,8 +407,8 @@ END
407407
//
408408

409409
VS_VERSION_INFO VERSIONINFO
410-
FILEVERSION 4,9,2254,0
411-
PRODUCTVERSION 4,9,2254,0
410+
FILEVERSION 4,9,2255,0
411+
PRODUCTVERSION 4,9,2255,0
412412
FILEFLAGSMASK 0x3fL
413413
#ifdef _DEBUG
414414
FILEFLAGS 0x1L
@@ -426,13 +426,13 @@ BEGIN
426426
VALUE "Comments", "https://rufus.ie"
427427
VALUE "CompanyName", "Akeo Consulting"
428428
VALUE "FileDescription", "Rufus"
429-
VALUE "FileVersion", "4.9.2254"
429+
VALUE "FileVersion", "4.9.2255"
430430
VALUE "InternalName", "Rufus"
431431
VALUE "LegalCopyright", "� 2011-2025 Pete Batard (GPL v3)"
432432
VALUE "LegalTrademarks", "https://www.gnu.org/licenses/gpl-3.0.html"
433433
VALUE "OriginalFilename", "rufus-4.9.exe"
434434
VALUE "ProductName", "Rufus"
435-
VALUE "ProductVersion", "4.9.2254"
435+
VALUE "ProductVersion", "4.9.2255"
436436
END
437437
END
438438
BLOCK "VarFileInfo"

0 commit comments

Comments
 (0)