Skip to content

Commit

Permalink
Don't prematurely abort URL validity check during semi-large redirects
Browse files Browse the repository at this point in the history
During some redirects we were already downloading enough data to warrant
aborting the download, leaving us with 302 as the last status code,
failing the reachable-URL test.

With this change, we will only start to count downloadable bytes once we
left the redirects, so we will only count downloaded data at our final
destination.

Resolves: #597
  • Loading branch information
ximion committed Feb 18, 2024
1 parent 29ea959 commit d3085b7
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/as-curl.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ as_curl_download_write_bytearray_cb (char *ptr, size_t size, size_t nmemb, void
GByteArray *buf = (GByteArray *) udata;
gsize realsize = size * nmemb;
g_byte_array_append (buf, (const guint8 *) ptr, realsize);

return realsize;
}

Expand Down Expand Up @@ -368,11 +369,18 @@ as_curl_progress_check_url_cb (void *clientp,
curl_off_t ulnow)
{
AsCurlPrivate *priv = GET_PRIVATE ((AsCurl *) clientp);
glong status_code;

/* always continue if we are still being redirected */
curl_easy_getinfo (priv->curl, CURLINFO_RESPONSE_CODE, &status_code);
if (status_code == 302)
return 0;

priv->bytes_downloaded = dlnow;

/* stop after 2kb have been successfully downloaded - it turns out a lot
/* stop after 1kb has been successfully downloaded - it turns out a lot
* of downloads fail later, so just checking for the first byte is not enough */
if (dlnow >= 2048)
if (dlnow >= 1024)
return 1;
return 0;
}
Expand Down

0 comments on commit d3085b7

Please sign in to comment.