aboutsummaryrefslogtreecommitdiff
path: root/src/libs/dutil/WixToolset.DUtil/dlutil.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/libs/dutil/WixToolset.DUtil/dlutil.cpp')
-rw-r--r--src/libs/dutil/WixToolset.DUtil/dlutil.cpp46
1 files changed, 39 insertions, 7 deletions
diff --git a/src/libs/dutil/WixToolset.DUtil/dlutil.cpp b/src/libs/dutil/WixToolset.DUtil/dlutil.cpp
index f6b793b2..9c704ee8 100644
--- a/src/libs/dutil/WixToolset.DUtil/dlutil.cpp
+++ b/src/libs/dutil/WixToolset.DUtil/dlutil.cpp
@@ -295,7 +295,10 @@ static HRESULT DownloadResource(
295 HANDLE hPayloadFile = INVALID_HANDLE_VALUE; 295 HANDLE hPayloadFile = INVALID_HANDLE_VALUE;
296 DWORD cbMaxData = 64 * 1024; // 64 KB 296 DWORD cbMaxData = 64 * 1024; // 64 KB
297 BYTE* pbData = NULL; 297 BYTE* pbData = NULL;
298 BOOL fRangeRequestsAccepted = TRUE; 298 BOOL fUseRangeRequest = TRUE;
299 BOOL fRangeRequestsAccepted = FALSE;
300 BOOL fRequestedRangeRequest = FALSE;
301 BOOL fInvalidRangeRequestResponse = FALSE;
299 LPWSTR sczRangeRequestHeader = NULL; 302 LPWSTR sczRangeRequestHeader = NULL;
300 HINTERNET hConnect = NULL; 303 HINTERNET hConnect = NULL;
301 HINTERNET hUrl = NULL; 304 HINTERNET hUrl = NULL;
@@ -315,10 +318,19 @@ static HRESULT DownloadResource(
315 // are not supported we'll have to start over and accept the fact that we only get one shot 318 // are not supported we'll have to start over and accept the fact that we only get one shot
316 // downloading the file however big it is. Hopefully, not more than 2 GB since wininet doesn't 319 // downloading the file however big it is. Hopefully, not more than 2 GB since wininet doesn't
317 // like files that big. 320 // like files that big.
318 while (fRangeRequestsAccepted && (0 == dw64ResourceLength || dw64ResumeOffset < dw64ResourceLength)) 321 for (;;)
319 { 322 {
320 hr = AllocateRangeRequestHeader(dw64ResumeOffset, 0 == dw64ResourceLength ? dw64AuthoredResourceLength : dw64ResourceLength, &sczRangeRequestHeader); 323 fInvalidRangeRequestResponse = FALSE;
321 DlExitOnFailure(hr, "Failed to allocate range request header."); 324
325 if (fUseRangeRequest)
326 {
327 hr = AllocateRangeRequestHeader(dw64ResumeOffset, 0 == dw64ResourceLength ? dw64AuthoredResourceLength : dw64ResourceLength, &sczRangeRequestHeader);
328 DlExitOnFailure(hr, "Failed to allocate range request header.");
329 }
330 else
331 {
332 ReleaseNullStr(sczRangeRequestHeader);
333 }
322 334
323 ReleaseNullInternet(hConnect); 335 ReleaseNullInternet(hConnect);
324 ReleaseNullInternet(hUrl); 336 ReleaseNullInternet(hUrl);
@@ -326,6 +338,13 @@ static HRESULT DownloadResource(
326 hr = MakeRequest(hSession, psczUrl, L"GET", sczRangeRequestHeader, wzUser, wzPassword, pAuthenticate, &hConnect, &hUrl, &fRangeRequestsAccepted); 338 hr = MakeRequest(hSession, psczUrl, L"GET", sczRangeRequestHeader, wzUser, wzPassword, pAuthenticate, &hConnect, &hUrl, &fRangeRequestsAccepted);
327 DlExitOnFailure(hr, "Failed to request URL for download: %ls", *psczUrl); 339 DlExitOnFailure(hr, "Failed to request URL for download: %ls", *psczUrl);
328 340
341 fRequestedRangeRequest = sczRangeRequestHeader && *sczRangeRequestHeader;
342
343 if (fRequestedRangeRequest && !fRangeRequestsAccepted)
344 {
345 LogStringLine(REPORT_VERBOSE, "Range request not supported for URL: %ls", *psczUrl);
346 }
347
329 // If we didn't get the size of the resource from the initial "HEAD" request 348 // If we didn't get the size of the resource from the initial "HEAD" request
330 // then let's try to get the size from this "GET" request. 349 // then let's try to get the size from this "GET" request.
331 if (0 == dw64ResourceLength) 350 if (0 == dw64ResourceLength)
@@ -337,23 +356,36 @@ static HRESULT DownloadResource(
337 } 356 }
338 else // server didn't tell us the resource length. 357 else // server didn't tell us the resource length.
339 { 358 {
359 LogStringLine(REPORT_VERBOSE, "Content-Length not returned for URL: %ls", *psczUrl);
360
340 // Fallback to the authored size of the resource. However, since we 361 // Fallback to the authored size of the resource. However, since we
341 // don't really know the size on the server, don't try to use 362 // don't really know the size on the server, don't try to use
342 // range requests either. 363 // range requests either.
343 dw64ResourceLength = dw64AuthoredResourceLength; 364 dw64ResourceLength = dw64AuthoredResourceLength;
365 fInvalidRangeRequestResponse = fRequestedRangeRequest;
344 fRangeRequestsAccepted = FALSE; 366 fRangeRequestsAccepted = FALSE;
345 } 367 }
346 } 368 }
347 369
348 // If we just tried to do a range request and found out that it isn't supported, start over. 370 // If we just tried to do a range request and found out that it isn't supported, ignore the offset.
349 if (!fRangeRequestsAccepted) 371 if (fRequestedRangeRequest && !fRangeRequestsAccepted)
350 { 372 {
351 // TODO: log a message that the server did not accept range requests.
352 dw64ResumeOffset = 0; 373 dw64ResumeOffset = 0;
374 fUseRangeRequest = FALSE;
375 }
376
377 if (fInvalidRangeRequestResponse)
378 {
379 continue;
353 } 380 }
354 381
355 hr = WriteToFile(hUrl, hPayloadFile, &dw64ResumeOffset, hResumeFile, dw64ResourceLength, pbData, cbMaxData, pCache); 382 hr = WriteToFile(hUrl, hPayloadFile, &dw64ResumeOffset, hResumeFile, dw64ResourceLength, pbData, cbMaxData, pCache);
356 DlExitOnFailure(hr, "Failed while reading from internet and writing to: %ls", wzDestinationPath); 383 DlExitOnFailure(hr, "Failed while reading from internet and writing to: %ls", wzDestinationPath);
384
385 if (!fUseRangeRequest || dw64ResumeOffset >= dw64ResourceLength)
386 {
387 break;
388 }
357 } 389 }
358 390
359LExit: 391LExit: