]> granicus.if.org Git - curl/commitdiff
alt-svc: send Alt-Used: in redirected requests
authorDaniel Stenberg <daniel@haxx.se>
Wed, 7 Aug 2019 18:43:18 +0000 (20:43 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Thu, 8 Aug 2019 06:24:37 +0000 (08:24 +0200)
RFC 7838 section 5:

   When using an alternative service, clients SHOULD include an Alt-Used
   header field in all requests.

Removed CURLALTSVC_ALTUSED again (feature is still EXPERIMENTAL thus
this is deemed ok).

You can disable sending this header just like you disable any other HTTP
header in libcurl.

Closes #4199

docs/libcurl/symbols-in-versions
include/curl/curl.h
lib/http.c
lib/url.c
lib/urldata.h

index 9a4cec2b0964288a769d268928201017aa5f5489..7897d7c2f14b765548409b2ed0f47e78a020824b 100644 (file)
@@ -12,7 +12,6 @@
 
  Name                           Introduced  Deprecated  Removed
 
-CURLALTSVC_ALTUSED              7.64.1
 CURLALTSVC_H1                   7.64.1
 CURLALTSVC_H2                   7.64.1
 CURLALTSVC_H3                   7.64.1
index 14703fd178568d952f669158423e332cfe44f29b..7b02846b4415e29911a89262c6f170d86c711826 100644 (file)
@@ -883,7 +883,7 @@ typedef enum {
 
 /* CURLALTSVC_* are bits for the CURLOPT_ALTSVC_CTRL option */
 #define CURLALTSVC_IMMEDIATELY  (1<<0)
-#define CURLALTSVC_ALTUSED      (1<<1)
+
 #define CURLALTSVC_READONLYFILE (1<<2)
 #define CURLALTSVC_H1           (1<<3)
 #define CURLALTSVC_H2           (1<<4)
index 546c34aadfe634c09cf250ef22b2bb67bf175820..73d52aee5181c61db4b4399af76c5e7551a48b26 100644 (file)
@@ -1998,6 +1998,7 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
   const char *httpstring;
   Curl_send_buffer *req_buffer;
   curl_off_t postsize = 0; /* curl_off_t to handle large file sizes */
+  char *altused = NULL;
 
   /* Always consider the DO phase done after this function call, even if there
      may be parts of the request that is not yet sent, since we can deal with
@@ -2592,6 +2593,14 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
   if(result)
     return result;
 
+#ifdef USE_ALTSVC
+  if(conn->bits.altused && !Curl_checkheaders(conn, "Alt-Used")) {
+    altused = aprintf("Alt-Used: %s:%d\r\n",
+                      conn->conn_to_host.name, conn->conn_to_port);
+    if(!altused)
+      return CURLE_OUT_OF_MEMORY;
+  }
+#endif
   result =
     Curl_add_bufferf(&req_buffer,
                      "%s" /* ftp typecode (;type=x) */
@@ -2606,7 +2615,8 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
                      "%s" /* accept-encoding */
                      "%s" /* referer */
                      "%s" /* Proxy-Connection */
-                     "%s",/* transfer-encoding */
+                     "%s" /* transfer-encoding */
+                     "%s",/* Alt-Used */
 
                      ftp_typecode,
                      httpstring,
@@ -2632,13 +2642,15 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
                       !conn->bits.tunnel_proxy &&
                       !Curl_checkProxyheaders(conn, "Proxy-Connection"))?
                      "Proxy-Connection: Keep-Alive\r\n":"",
-                     te
+                     te,
+                     altused ? altused : ""
       );
 
   /* clear userpwd and proxyuserpwd to avoid re-using old credentials
    * from re-used connections */
   Curl_safefree(conn->allocptr.userpwd);
   Curl_safefree(conn->allocptr.proxyuserpwd);
+  free(altused);
 
   if(result)
     return result;
index 99bea3f0154d25cc5cba510ea5fc840d5026ddf9..d31f83065abdb6ba5c47eebddb8a646107224a6e 100644 (file)
--- a/lib/url.c
+++ b/lib/url.c
@@ -3187,6 +3187,7 @@ static CURLcode parse_connect_to_slist(struct Curl_easy *data,
       conn->bits.conn_to_host = TRUE;
       conn->conn_to_port = nport;
       conn->bits.conn_to_port = TRUE;
+      conn->bits.altused = TRUE;
       infof(data, "Alt-svc connecting from [%s]%s:%d to [%s]%s:%d\n",
             Curl_alpnid2str(salpnid), host, conn->remote_port,
             Curl_alpnid2str(nalpnid), hostd, nport);
index 395664d04d986e2059394c252215bccc78cc9fa8..3129cb3ce715ef16a71eac8078b8a99e9955502d 100644 (file)
@@ -405,6 +405,7 @@ struct ConnectBits {
                          the first time on the first connect function call */
   bit close:1; /* if set, we close the connection after this request */
   bit reuse:1; /* if set, this is a re-used connection */
+  bit altused:1; /* this is an alt-svc "redirect" */
   bit conn_to_host:1; /* if set, this connection has a "connect to host"
                          that overrides the host in the URL */
   bit conn_to_port:1; /* if set, this connection has a "connect to port"