summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMax Dymond <max.dymond@microsoft.com>2021-07-22 15:32:30 +0100
committerDaniel Stenberg <daniel@haxx.se>2021-09-27 17:16:43 +0200
commita517378de58358a85b7cfe9efecb56051268f629 (patch)
tree8b8b43685911d3cbc6450b8d7255f5a10d2b8795 /lib
parent06981ba7f620364eba253f5afcd7ebfaefcc8694 (diff)
downloadcurl-a517378de58358a85b7cfe9efecb56051268f629.tar.gz
CURLOPT_PREREQFUNCTION: add new callback
Triggered before a request is made but after a connection is set up Changes: - callback: Update docs and callback for pre-request callback - Add documentation for CURLOPT_PREREQDATA and CURLOPT_PREREQFUNCTION, - Add redirect test and callback failure test - Note that the function may be called multiple times on a redirection - Disable new 2086 test due to Windows weirdness Closes #7477
Diffstat (limited to 'lib')
-rw-r--r--lib/easyoptions.c2
-rw-r--r--lib/multi.c22
-rw-r--r--lib/setopt.c6
-rw-r--r--lib/urldata.h2
4 files changed, 31 insertions, 1 deletions
diff --git a/lib/easyoptions.c b/lib/easyoptions.c
index b1c0704d5..717b081a3 100644
--- a/lib/easyoptions.c
+++ b/lib/easyoptions.c
@@ -356,6 +356,6 @@ struct curl_easyoption Curl_easyopts[] = {
*/
int Curl_easyopts_check(void)
{
- return ((CURLOPT_LASTENTRY%10000) != (311 + 1));
+ return ((CURLOPT_LASTENTRY%10000) != (313 + 1));
}
#endif
diff --git a/lib/multi.c b/lib/multi.c
index 68c1a64d5..f31b25262 100644
--- a/lib/multi.c
+++ b/lib/multi.c
@@ -2028,6 +2028,28 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi,
break;
case MSTATE_DO:
+ if(data->set.fprereq) {
+ int prereq_rc;
+
+ /* call the prerequest callback function */
+ Curl_set_in_callback(data, true);
+ prereq_rc = data->set.fprereq(data->set.prereq_userp,
+ data->info.conn_primary_ip,
+ data->info.conn_local_ip,
+ data->info.conn_primary_port,
+ data->info.conn_local_port);
+ Curl_set_in_callback(data, false);
+ if(prereq_rc != CURL_PREREQFUNC_OK) {
+ failf(data, "operation aborted by pre-request callback");
+ /* failure in pre-request callback - don't do any other processing */
+ result = CURLE_ABORTED_BY_CALLBACK;
+ Curl_posttransfer(data);
+ multi_done(data, result, FALSE);
+ stream_error = TRUE;
+ break;
+ }
+ }
+
if(data->set.connect_only) {
/* keep connection open for application to use the socket */
connkeep(data->conn, "CONNECT_ONLY");
diff --git a/lib/setopt.c b/lib/setopt.c
index c62a62fb5..8e19389ae 100644
--- a/lib/setopt.c
+++ b/lib/setopt.c
@@ -3013,6 +3013,12 @@ CURLcode Curl_vsetopt(struct Curl_easy *data, CURLoption option, va_list param)
return result;
break;
#endif
+ case CURLOPT_PREREQFUNCTION:
+ data->set.fprereq = va_arg(param, curl_prereq_callback);
+ break;
+ case CURLOPT_PREREQDATA:
+ data->set.prereq_userp = va_arg(param, void *);
+ break;
default:
/* unknown tag and its companion, just ignore: */
result = CURLE_UNKNOWN_OPTION;
diff --git a/lib/urldata.h b/lib/urldata.h
index 2d1e873a5..47cb9e282 100644
--- a/lib/urldata.h
+++ b/lib/urldata.h
@@ -1652,6 +1652,8 @@ struct UserDefined {
curl_closesocket_callback fclosesocket; /* function for closing the
socket */
void *closesocket_client;
+ curl_prereq_callback fprereq; /* pre-initial request callback */
+ void *prereq_userp; /* pre-initial request user data */
void *seek_client; /* pointer to pass to the seek callback */
/* the 3 curl_conv_callback functions below are used on non-ASCII hosts */