From a56f81c1777f694dbe3377557ebbd6532c64e90d Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Fri, 12 Aug 2016 13:02:17 +0200 Subject: [PATCH 1/1] libalpm/dload: handle security gateways with graceful low speed time Security gateways inspect the file content and take some time doing so. For huge download files the previous default of 10 seconds is not enough, so increase the default value and decrease in progress callback once we received some data. Signed-off-by: Christian Hesse --- lib/libalpm/dload.c | 17 ++++++++++++++++- lib/libalpm/dload.h | 1 + 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/libalpm/dload.c b/lib/libalpm/dload.c index 31ae82c..bef4ce3 100644 --- a/lib/libalpm/dload.c +++ b/lib/libalpm/dload.c @@ -96,6 +96,15 @@ static int dload_progress_cb(void *file, double dltotal, double dlnow, struct dload_payload *payload = (struct dload_payload *)file; off_t current_size, total_size; +#ifdef HAVE_LIBCURL + /* Decrease the low speed time once data has been received. Security + * gateways should have finished inspecting the file. We want to + * catch stalled connections now. */ + if(dlnow > 0L) { + curl_easy_setopt(payload->curl, CURLOPT_LOW_SPEED_TIME, 10L); + } +#endif + /* avoid displaying progress bar for redirects with a body */ if(payload->respcode >= 300) { return 0; @@ -296,7 +305,11 @@ static void curl_set_handle_opts(struct dload_payload *payload, curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, dload_progress_cb); curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, (void *)payload); curl_easy_setopt(curl, CURLOPT_LOW_SPEED_LIMIT, 1L); - curl_easy_setopt(curl, CURLOPT_LOW_SPEED_TIME, 10L); + /* Security gateways inspect the file content and take some time doing so. + * For huge download files the previous default of 10 seconds is not + * enough, so increase the value here and decrease in progress callback + * once we received some data. */ + curl_easy_setopt(curl, CURLOPT_LOW_SPEED_TIME, 60L); curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, dload_parseheader_cb); curl_easy_setopt(curl, CURLOPT_WRITEHEADER, (void *)payload); curl_easy_setopt(curl, CURLOPT_NETRC, CURL_NETRC_OPTIONAL); @@ -404,6 +417,8 @@ static int curl_download_internal(struct dload_payload *payload, CURL *curl = get_libcurl_handle(handle); handle->pm_errno = 0; + payload->curl = curl; + /* make sure these are NULL */ FREE(payload->tempfile_name); FREE(payload->destfile_name); diff --git a/lib/libalpm/dload.h b/lib/libalpm/dload.h index 60843bd..667263b 100644 --- a/lib/libalpm/dload.h +++ b/lib/libalpm/dload.h @@ -42,6 +42,7 @@ struct dload_payload { int unlink_on_fail; int trust_remote_name; #ifdef HAVE_LIBCURL + CURL *curl; CURLcode curlerr; /* last error produced by curl */ #endif }; -- 2.9.2