libcpr / cpr

C++ Requests: Curl for People, a spiritual port of Python Requests.
https://docs.libcpr.org/
Other
6.29k stars 903 forks source link

Session with different urls #1058

Closed a412h closed 4 weeks ago

a412h commented 4 weeks ago

This is not a bug of the library, only a question. Let us say that I have to maintain a connection to two different urls (same base url, but two different endpoints) with a Session object. What is the recommended approach ? Should I instantiate one session object, and change the url in the session object each time before a message is sent ? For example, with two different urls:

cpr::Session session;

session.SetUrl(cpr::Url{url1});
cpr::Response r1 = session.Post();

session.SetUrl(cpr::Url{url2});
cpr::Response r2 = session.Post();

Is that efficient ? What would be the recommended approach ?

COM8 commented 4 weeks ago

Go with two sessions since that way you keep the session stats. Else every request would initiate a new SSL handshake, which is slow.

a412h commented 4 weeks ago

Thank you for the prompt and clear response.