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
This commit is contained in:
Max Dymond 2021-07-22 15:32:30 +01:00 committed by Daniel Stenberg
parent 06981ba7f6
commit a517378de5
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
21 changed files with 602 additions and 4 deletions

View file

@ -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

View file

@ -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");

View file

@ -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;

View file

@ -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 */