与 libcurl 的持久连接

Persistent connection with libcurl

以下内容来自libcurl主页:

curl and libcurl have excellent support for persistent connections when transferring several files from the same server. Curl will attempt to reuse connections for all URLs specified on the same command line/config file, and libcurl will reuse connections for all transfers that are made using the same libcurl handle.

只是为了确定,如果我创建一个 CURL 句柄 (curl_easy_init()) 并将其设置为 headers,创建一个 HTTP-request,然后更改 headers并发出另一个请求,libcurl 仍将尝试使用持久连接,即使 headers 已更改?

libcurl主页也说

If you use the easy interface, and you call curl_easy_cleanup, all the possibly open connections held by libcurl will be closed and forgotten.

因此,只要我不调用 curl_easy_cleanup,CURL 就会尝试 re-use 相同的连接,即使请求是使用不同的 headers?

谢谢。

是的,完全正确。继续重复使用相同的简单句柄,libcurl 将尝试尽可能多地重复使用连接。