From 4bb205d4404de6a1e14df975aa04de26b84615c1 Mon Sep 17 00:00:00 2001 From: Yat Ho Date: Mon, 4 Sep 2023 07:26:39 +0800 Subject: [PATCH] fix: workaround HSTS upgrading to HTTPS for HTTP trackers (#5969) --- libtransmission/web.cc | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/libtransmission/web.cc b/libtransmission/web.cc index 343318510..ee8660b46 100644 --- a/libtransmission/web.cc +++ b/libtransmission/web.cc @@ -166,7 +166,7 @@ public: curl_ca_bundle = std::move(bundle); } - shareEverything(); + share_setopt(); if (curl_ssl_verify) { @@ -757,24 +757,23 @@ public: return curlsh_.get(); } - void shareEverything() + void share_setopt() { - // Tell curl to share whatever it can. - // https://curl.se/libcurl/c/CURLSHOPT_SHARE.html - // - // The user's system probably has a different version of curl than - // we're compiling with; so instead of listing fields by name, just - // loop until curl says we've exhausted the list. + // Do *not* share HSTS cache + // https://github.com/transmission/transmission/issues/5199 auto* const sh = shared(); - for (long type = CURL_LOCK_DATA_COOKIE;; ++type) - { - if (curl_share_setopt(sh, CURLSHOPT_SHARE, type) != CURLSHE_OK) - { - tr_logAddDebug(fmt::format("CURLOPT_SHARE ended at {}", type)); - return; - } - } + curl_share_setopt(sh, CURLSHOPT_SHARE, CURL_LOCK_DATA_COOKIE); + curl_share_setopt(sh, CURLSHOPT_SHARE, CURL_LOCK_DATA_DNS); +#if LIBCURL_VERSION_NUM >= 0x071700 /* 7.23.0 */ + curl_share_setopt(sh, CURLSHOPT_SHARE, CURL_LOCK_DATA_SSL_SESSION); +#endif +#if LIBCURL_VERSION_NUM >= 0x073900 /* 7.57.0 */ + curl_share_setopt(sh, CURLSHOPT_SHARE, CURL_LOCK_DATA_CONNECT); +#endif +#if LIBCURL_VERSION_NUM >= 0x073D00 /* 7.61.0 */ + curl_share_setopt(sh, CURLSHOPT_SHARE, CURL_LOCK_DATA_PSL); +#endif } static inline auto curl_init_flag = std::once_flag{};