]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
alt-svc: honor data->state.httpwant
authorStefan Eissing <stefan@eissing.org>
Thu, 19 Sep 2024 10:23:55 +0000 (12:23 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Fri, 20 Sep 2024 21:35:29 +0000 (23:35 +0200)
When a transfer is set for a speficif HTTP version, only lookup that
protocol in the alt-svc mappings. When no speicific version is
requested, scan all entries as before.

Closes #14966

lib/url.c

index 93fbdb92a3bdbf783a2c3b1baea949ac27cc6b53..01b6fb5bc5432d6e9c3f7a014304d3ad11f7853f 100644 (file)
--- a/lib/url.c
+++ b/lib/url.c
@@ -3027,9 +3027,10 @@ static CURLcode parse_connect_to_slist(struct Curl_easy *data,
 #endif
        )) {
     /* no connect_to match, try alt-svc! */
-    enum alpnid srcalpnid;
+    enum alpnid srcalpnid = ALPN_none;
+    bool use_alt_svc = FALSE;
     bool hit = FALSE;
-    struct altsvc *as;
+    struct altsvc *as = NULL;
     const int allowed_versions = ( ALPN_h1
 #ifdef USE_HTTP2
                                    | ALPN_h2
@@ -3038,7 +3039,7 @@ static CURLcode parse_connect_to_slist(struct Curl_easy *data,
                                    | ALPN_h3
 #endif
       ) & data->asi->flags;
-    static int alpn_ids[] = {
+    static enum alpnid alpn_ids[] = {
 #ifdef USE_HTTP3
       ALPN_h3,
 #endif
@@ -3049,16 +3050,54 @@ static CURLcode parse_connect_to_slist(struct Curl_easy *data,
     };
     size_t i;
 
+    switch(data->state.httpwant) {
+    case CURL_HTTP_VERSION_1_0:
+      break;
+    case CURL_HTTP_VERSION_1_1:
+      use_alt_svc = TRUE;
+      srcalpnid = ALPN_h1; /* only regard alt-svc advice for http/1.1 */
+      break;
+    case CURL_HTTP_VERSION_2_0:
+      use_alt_svc = TRUE;
+      srcalpnid = ALPN_h2; /* only regard alt-svc advice for h2 */
+      break;
+    case CURL_HTTP_VERSION_2_PRIOR_KNOWLEDGE:
+      break;
+    case CURL_HTTP_VERSION_3:
+      use_alt_svc = TRUE;
+      srcalpnid = ALPN_h3; /* only regard alt-svc advice for h3 */
+      break;
+    case CURL_HTTP_VERSION_3ONLY:
+      break;
+    default: /* no specific HTTP version wanted, look at all of alt-svc */
+      use_alt_svc = TRUE;
+      srcalpnid = ALPN_none;
+      break;
+    }
+    if(!use_alt_svc)
+      return CURLE_OK;
+
     host = conn->host.rawalloc;
     DEBUGF(infof(data, "check Alt-Svc for host %s", host));
-    for(i = 0; !hit && (i < ARRAYSIZE(alpn_ids)); ++i) {
-      srcalpnid = alpn_ids[i];
+    if(srcalpnid == ALPN_none) {
+      /* scan all alt-svc protocol ids in order or relevance */
+      for(i = 0; !hit && (i < ARRAYSIZE(alpn_ids)); ++i) {
+        srcalpnid = alpn_ids[i];
+        hit = Curl_altsvc_lookup(data->asi,
+                                 srcalpnid, host, conn->remote_port, /* from */
+                                 &as /* to */,
+                                 allowed_versions);
+      }
+    }
+    else {
+      /* look for a specific alt-svc protocol id */
       hit = Curl_altsvc_lookup(data->asi,
                                srcalpnid, host, conn->remote_port, /* from */
                                &as /* to */,
                                allowed_versions);
     }
 
+
     if(hit) {
       char *hostd = strdup((char *)as->dst.host);
       if(!hostd)