]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
cfilters: CF_TYPE_SETUP connection filter
authorStefan Eissing <stefan@eissing.org>
Wed, 8 Apr 2026 12:37:45 +0000 (14:37 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Thu, 9 Apr 2026 12:10:28 +0000 (14:10 +0200)
Connection filters can now carry the flag CF_TYPE_SETUP, indicating that
they are only needed during connection setup, e.g. connect.

Once the connection is fully established, those filter are removed
again. This frees resources and also makes the filter (call) chains
shorter.

Closes #21269

lib/cf-dns.c
lib/cf-haproxy.c
lib/cf-https-connect.c
lib/cf-ip-happy.c
lib/cfilters.c
lib/cfilters.h
lib/http_proxy.c

index 437a3491c33ae5443d9da2bfdc3e7f2f181ada4a..c9df2ff93f79e1dd2c338bb5126d5bc85ca0e226 100644 (file)
@@ -306,7 +306,7 @@ static CURLcode cf_dns_cntrl(struct Curl_cfilter *cf,
 
 struct Curl_cftype Curl_cft_dns = {
   "DNS",
-  0,
+  CF_TYPE_SETUP,
   CURL_LOG_LVL_NONE,
   cf_dns_destroy,
   cf_dns_connect,
index 782253e83e2ea111f8b49662b1406803c870d84c..46d0541055d203f252ae4e0fc8b3368abeeb8009 100644 (file)
@@ -185,7 +185,7 @@ static CURLcode cf_haproxy_adjust_pollset(struct Curl_cfilter *cf,
 
 struct Curl_cftype Curl_cft_haproxy = {
   "HAPROXY",
-  CF_TYPE_PROXY,
+  CF_TYPE_PROXY | CF_TYPE_SETUP,
   0,
   cf_haproxy_destroy,
   cf_haproxy_connect,
index b07631ac400416884dc9e3ae4a6c18d079d64147..5434cd7ed63b0a49f9718b1e1b12ef0a49dc4c50 100644 (file)
@@ -743,7 +743,7 @@ static void cf_hc_destroy(struct Curl_cfilter *cf, struct Curl_easy *data)
 
 struct Curl_cftype Curl_cft_http_connect = {
   "HTTPS-CONNECT",
-  0,
+  CF_TYPE_SETUP,
   CURL_LOG_LVL_NONE,
   cf_hc_destroy,
   cf_hc_connect,
index 0659f56aededc12452ffd843c3cd3856e7f19f30..2558053b47cd8c9f389c27ce12c389b891c8fa73 100644 (file)
@@ -958,7 +958,7 @@ static void cf_ip_happy_destroy(struct Curl_cfilter *cf,
 
 struct Curl_cftype Curl_cft_ip_happy = {
   "HAPPY-EYEBALLS",
-  0,
+  CF_TYPE_SETUP,
   CURL_LOG_LVL_NONE,
   cf_ip_happy_destroy,
   cf_ip_happy_connect,
index 41e09bc9fcf9dbe41f5ed2687975e189232372e7..2f8fd4a6b0bb37b8e762f9be7fcbfcff36a5c3f7 100644 (file)
@@ -491,6 +491,24 @@ static void conn_report_connect_stats(struct Curl_cfilter *cf,
   }
 }
 
+static void conn_remove_setup_filters(struct Curl_easy *data,
+                                      int sockindex)
+{
+  struct Curl_cfilter **anchor = &data->conn->cfilter[sockindex];
+  while(*anchor) {
+    struct Curl_cfilter *cf = *anchor;
+    if(cf->connected && (cf->cft->flags & CF_TYPE_SETUP)) {
+      *anchor = cf->next;
+      cf->next = NULL;
+      CURL_TRC_CF(data, cf, "removing connected setup filter");
+      cf->cft->destroy(cf, data);
+      curlx_free(cf);
+    }
+    else
+      anchor = &cf->next;
+  }
+}
+
 CURLcode Curl_conn_connect(struct Curl_easy *data,
                            int sockindex,
                            bool blocking,
@@ -544,6 +562,7 @@ CURLcode Curl_conn_connect(struct Curl_easy *data,
       conn_report_connect_stats(cf, data);
       data->conn->keepalive = *Curl_pgrs_now(data);
       VERBOSE(result = cf_verboseconnect(data, cf));
+      conn_remove_setup_filters(data, sockindex);
       goto out;
     }
     else if(result) {
index 77405b51adc518fbc91e46dbd8c350a6853b33f9..38311b24b8300c46a2cce0b3baea0848d54ad208 100644 (file)
@@ -199,12 +199,15 @@ typedef CURLcode Curl_cft_query(struct Curl_cfilter *cf,
  * CF_TYPE_MULTIPLEX:  provides multiplexing of easy handles
  * CF_TYPE_PROXY       provides proxying
  * CF_TYPE_HTTP        implement a version of the HTTP protocol
+ * CF_TYPE_SETUP       filter is only needed for connection setup and
+ *                     can be removed once connected
  */
 #define CF_TYPE_IP_CONNECT  (1 << 0)
 #define CF_TYPE_SSL         (1 << 1)
 #define CF_TYPE_MULTIPLEX   (1 << 2)
 #define CF_TYPE_PROXY       (1 << 3)
 #define CF_TYPE_HTTP        (1 << 4)
+#define CF_TYPE_SETUP       (1 << 5)
 
 /* A connection filter type, e.g. specific implementation. */
 struct Curl_cftype {
index 5996c12f4e25e3116be8d7edc791eb3e38102f0e..4bdfe2224087441b7123b8f2f898d6b5b308743b 100644 (file)
@@ -391,7 +391,7 @@ static void http_proxy_cf_close(struct Curl_cfilter *cf,
 
 struct Curl_cftype Curl_cft_http_proxy = {
   "HTTP-PROXY",
-  CF_TYPE_IP_CONNECT | CF_TYPE_PROXY,
+  CF_TYPE_IP_CONNECT | CF_TYPE_PROXY | CF_TYPE_SETUP,
   0,
   http_proxy_cf_destroy,
   http_proxy_cf_connect,