Skip to content

Commit

Permalink
Simplify setting CURLOPT_PROXY.
Browse files Browse the repository at this point in the history
  • Loading branch information
skullernet authored and res2k committed Nov 4, 2023
1 parent db19a5b commit 6bc88cb
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/client/http.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,14 @@ static const char *http_gamedir(void)
return BASEGAME;
}

static const char *http_proxy(void)
{
if (*cl_http_proxy->string)
return cl_http_proxy->string;

return NULL;
}

// Actually starts a download by adding it to the curl multi handle.
static bool start_download(dlqueue_t *entry, dlhandle_t *dl)
{
Expand Down Expand Up @@ -307,10 +315,7 @@ static bool start_download(dlqueue_t *entry, dlhandle_t *dl)
curl_easy_setopt(dl->curl, CURLOPT_WRITEFUNCTION, recv_func);
curl_easy_setopt(dl->curl, CURLOPT_MAXFILESIZE, MAX_DLSIZE - 1L);
}
if (*cl_http_proxy->string)
curl_easy_setopt(dl->curl, CURLOPT_PROXY, cl_http_proxy->string);
else
curl_easy_setopt(dl->curl, CURLOPT_PROXY, NULL);
curl_easy_setopt(dl->curl, CURLOPT_PROXY, http_proxy());
curl_easy_setopt(dl->curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(dl->curl, CURLOPT_MAXREDIRS, 5L);
curl_easy_setopt(dl->curl, CURLOPT_XFERINFOFUNCTION, progress_func);
Expand Down Expand Up @@ -372,8 +377,7 @@ int HTTP_FetchFile(const char *url, void **data)
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, recv_func);
curl_easy_setopt(curl, CURLOPT_MAXFILESIZE, MAX_DLSIZE - 1L);
curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1L);
if (*cl_http_proxy->string)
curl_easy_setopt(curl, CURLOPT_PROXY, cl_http_proxy->string);
curl_easy_setopt(curl, CURLOPT_PROXY, http_proxy());
curl_easy_setopt(curl, CURLOPT_USERAGENT, com_version->string);
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS | 0L);
Expand Down

0 comments on commit 6bc88cb

Please sign in to comment.