From 01603f988ec9b21b88b9aa0b04e291eefa0a3ff0 Mon Sep 17 00:00:00 2001 From: User Date: Wed, 23 Apr 2025 13:13:10 +0300 Subject: [PATCH] first draft formating Co-authored-by: Viktor Szakats Update lib/url.c Co-authored-by: Viktor Szakats Update docs/libcurl/opts/CURLOPT_ALTSVC_CTRL.md Co-authored-by: Daniel Stenberg --- docs/libcurl/opts/CURLOPT_ALTSVC_CTRL.md | 6 +++ docs/libcurl/symbols-in-versions | 1 + include/curl/curl.h | 1 + lib/url.c | 37 ++++++++++++-- tests/data/Makefile.am | 2 + tests/data/test3300 | 63 ++++++++++++++++++++++++ 6 files changed, 106 insertions(+), 4 deletions(-) create mode 100644 tests/data/test3300 diff --git a/docs/libcurl/opts/CURLOPT_ALTSVC_CTRL.md b/docs/libcurl/opts/CURLOPT_ALTSVC_CTRL.md index 84e5d6657c..9024bd84fd 100644 --- a/docs/libcurl/opts/CURLOPT_ALTSVC_CTRL.md +++ b/docs/libcurl/opts/CURLOPT_ALTSVC_CTRL.md @@ -26,6 +26,7 @@ CURLOPT_ALTSVC_CTRL - control alt-svc behavior #define CURLALTSVC_H1 (1L<<3) #define CURLALTSVC_H2 (1L<<4) #define CURLALTSVC_H3 (1L<<5) +#define CURLALTSVC_NO_RETRY (1L<<6) CURLcode curl_easy_setopt(CURL *handle, CURLOPT_ALTSVC_CTRL, long bitmask); ~~~ @@ -51,6 +52,11 @@ versions. Setting any bit enables the alt-svc engine. +If the connection fails when trying to connect to an alternative host, +the hostname from the URL is attempted instead. + +Failed connection problems that trigger this fallback include: ... + ## CURLALTSVC_READONLYFILE Do not write the alt-svc cache back to the file specified with diff --git a/docs/libcurl/symbols-in-versions b/docs/libcurl/symbols-in-versions index bfcf357bf6..e91cb6da73 100644 --- a/docs/libcurl/symbols-in-versions +++ b/docs/libcurl/symbols-in-versions @@ -199,6 +199,7 @@ CURLALTSVC_H1 7.64.1 CURLALTSVC_H2 7.64.1 CURLALTSVC_H3 7.64.1 CURLALTSVC_READONLYFILE 7.64.1 +CURLALTSVC_NO_RETRY 8.14.0 CURLAUTH_ANY 7.10.6 CURLAUTH_ANYSAFE 7.10.6 CURLAUTH_AWS_SIGV4 7.75.0 diff --git a/include/curl/curl.h b/include/curl/curl.h index 6f4aa90f13..d6ee4bc4c1 100644 --- a/include/curl/curl.h +++ b/include/curl/curl.h @@ -1032,6 +1032,7 @@ typedef enum { #define CURLALTSVC_H1 (1L<<3) #define CURLALTSVC_H2 (1L<<4) #define CURLALTSVC_H3 (1L<<5) +#define CURLALTSVC_NO_RETRY (1L<<6) /* bitmask values for CURLOPT_UPLOAD_FLAGS */ #define CURLULFLAG_ANSWERED (1L<<0) diff --git a/lib/url.c b/lib/url.c index 20161cac44..d111ef8119 100644 --- a/lib/url.c +++ b/lib/url.c @@ -3426,7 +3426,9 @@ static void conn_meta_freeentry(void *p) static CURLcode create_conn(struct Curl_easy *data, struct connectdata **in_connect, - bool *reusedp) + bool *reusedp, + bool *async, + bool *use_slist) { CURLcode result = CURLE_OK; struct connectdata *conn; @@ -3537,9 +3539,12 @@ static CURLcode create_conn(struct Curl_easy *data, * Process the "connect to" linked list of hostname/port mappings. * Do this after the remote port number has been fixed in the URL. *************************************************************/ - result = parse_connect_to_slist(data, conn, data->set.connect_to); - if(result) - goto out; + if(*use_slist) { + *use_slist = FALSE; /* next retry without slist */ + result = parse_connect_to_slist(data, conn, data->set.connect_to); + if(result) + goto out; + } /************************************************************* * IDN-convert the proxy hostnames @@ -3851,7 +3856,11 @@ CURLcode Curl_connect(struct Curl_easy *data, { CURLcode result; struct connectdata *conn; +<<<<<<< HEAD bool reused = FALSE; +======= + bool use_slist = TRUE; /* start by attempting to use the slist */ +>>>>>>> 3edfc1476 (first draft) *asyncp = FALSE; /* assume synchronous resolves by default */ *protocol_done = FALSE; @@ -3860,12 +3869,32 @@ CURLcode Curl_connect(struct Curl_easy *data, Curl_req_hard_reset(&data->req, data); /* call the stuff that needs to be called */ +<<<<<<< HEAD result = create_conn(data, &conn, &reused); if(result == CURLE_NO_CONNECTION_AVAILABLE) { DEBUGASSERT(!conn); return result; } +======= + result = create_conn(data, &conn, asyncp, &use_slist); + +#ifndef CURL_DISABLE_ALTSVC + /* if we failed because of the avc cache retry */ + if(result && data-> asi + && !use_slist + && !(data-> asi-> flags & CURLALTSVC_NO_RETRY) + ) { + if(conn && result != CURLE_NO_CONNECTION_AVAILABLE) { + Curl_detach_connection(data); + Curl_conn_terminate(data, conn, TRUE); + } + + Curl_req_hard_reset(&data->req, data); + result = create_conn(data, &conn, asyncp, &use_slist); + } +#endif +>>>>>>> 3edfc1476 (first draft) if(!result) { DEBUGASSERT(conn); diff --git a/tests/data/Makefile.am b/tests/data/Makefile.am index d0696da3de..558c50cb3e 100644 --- a/tests/data/Makefile.am +++ b/tests/data/Makefile.am @@ -280,5 +280,7 @@ test3100 test3101 test3102 test3103 test3104 test3105 \ test3200 test3201 test3202 test3203 test3204 test3205 test3207 test3208 \ test3209 test3210 test3211 test3212 test3213 test3214 test3215 \ test4000 test4001 +test3209 test3210 test3211 test3212 test3213 test3214 \ +test3300 EXTRA_DIST = $(TESTCASES) DISABLED diff --git a/tests/data/test3300 b/tests/data/test3300 new file mode 100644 index 0000000000..62dca5070d --- /dev/null +++ b/tests/data/test3300 @@ -0,0 +1,63 @@ + + + +HTTP +HTTP GET +Alt-Svc +onion + + + +# +# Server-side + + +HTTP/1.1 200 OK +Date: Tue, 09 Nov 2010 14:49:00 GMT +Content-Length: 6 +Connection: close +Content-Type: text/html +Funny-head: yesyes + +-foo- + + + +# +# Client-side + + +alt-svc +Debug + + +http + + +alt-svc using to an onion server + + +# make debug-curl accept Alt-Svc over plain HTTP +CURL_ALTSVC_HTTP="yeah" + + +--alt-svc "%LOGDIR/altsvc-%TESTNUMBER" "http://%HOSTIP:%HTTPPORT/%TESTNUMBER" + + +h1 %HOSTIP %HTTPPORT h1 bad.onion %HTTPPORT "20290222 22:19:28" 0 0 + + + + +# +# Verify data after the test has been "shot" + + +GET /%TESTNUMBER HTTP/1.1 +Host: %HOSTIP:%HTTPPORT +User-Agent: curl/%VERSION +Accept: */* + + + +