You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Also, you could use `cpr::Session` to make the connection stateful:
270
+
Also, you could use `cpr::Session` to make the connection stateful:
271
271
272
272
{% raw %}
273
273
```c++
@@ -310,7 +310,7 @@ cpr::Response r = fr.get(); // This blocks until the request is complete
310
310
std::cout << r.text << std::endl;
311
311
```
312
312
313
-
The call is otherwise identical except instead of `Get`, it's `GetAsync`. Similarly for POST requests, you would call `PostAsync`. The return value of an asynchronous call is actually a `std::future<Response>`:
313
+
The call is otherwise identical except instead of `Get`, it's `GetAsync`. Similarly for POST requests, you would call `PostAsync`. The return value of an asynchronous call is actually an `AsyncWrapper<Response>`, which exposes public member functions analogous to those of [`std::future<T>`](https://en.cppreference.com/w/cpp/thread/future):
Alternatively, you can use the `Multi<method>Async` to bundle multiple requests and execute them in parallel. The requests' parameters are delivered as positional arguments to an async method of your choice, packed in `std::tuple` or `std::array`s, just like the `Multi<method>` API functions. `MultiAsync` makes use of `cpr`'s threadpool-based parallelism, and also offers the capability to **cancel transactions** while they are underway. Here's an example:
340
+
341
+
{% raw %}
342
+
```c++
343
+
// The second template parameter denotes a cancellable transaction
344
+
using AsyncResC = cpr::AsyncWrapper<Response, true>;
Asynchronous requests can also be performed using a `cpr::Session` object. It is important to note that the asynchronous request is performed directly on the session object, modifying it in the process.
340
366
To ensure that the lifetime of the session is properly extended, the session object used **must be** managed by a `std::shared_ptr`. This restriction is necessary because the implementation uses `std::shared_from_this` to pass a pointer to the ansynchronous lambda function which would otherwise throw a `std::bad_weak_ptr` exception.
341
367
Here is an example for an asynchronous get request which uses a session object:
@@ -586,7 +612,7 @@ for(const auto &cookie : r.cookies) {
586
612
std::cout << cookie.GetExpiresString() << ":";
587
613
std::cout << cookie.GetName() << ":";
588
614
std::cout << cookie.GetValue() << std::endl;
589
-
// For example, this will print:
615
+
// For example, this will print:
590
616
// www.httpbin.org:0:/:0:Thu, 01 Jan 1970 00:00:00 GMT:cookies:yummy
@@ -1141,7 +1167,7 @@ Cpr offers the possibility to pass user-implemented interceptors to a session, w
1141
1167
### Single Session
1142
1168
1143
1169
Each interceptor implementation must inherit from the abstract class `cpr::Interceptor` for intercepting regular `cpr::Sessions` objects.
1144
-
The inherited class has to implement the function `cpr::Response intercept(cpr::Session& session)`.
1170
+
The inherited class has to implement the function `cpr::Response intercept(cpr::Session& session)`.
1145
1171
This function is automatically called for every added interceptor during the request with the session object belonging to the request passed as a parameter.
1146
1172
An essential point of the intercept function is that it must call the `cpr::Response proceed(Session& session)` function implemented in `cpr::Interceptor`.
1147
1173
This is necessary to continue the request and get the `cpr::Response` object.
It should be noted that interceptors can make changes to the session object that is later passed to the proceed function and can thus fundamentally change the request. Of course, the returned response object can also be modified.
1227
+
It should be noted that interceptors can make changes to the session object that is later passed to the proceed function and can thus fundamentally change the request. Of course, the returned response object can also be modified.
1202
1228
1203
1229
In addition, interceptors can even change the http method of the request by passing the proceed method another parameter of the enum type `cpr::Interceptor::ProceedHttpMethod`. The parameter required for download requests is also simply passed to the proceed method. For example we can implement an interceptor which changes the request method to `HEAD`:
1204
1230
@@ -1218,7 +1244,7 @@ class ChangeRequestMethodToHeadInterceptor : public Interceptor {
1218
1244
1219
1245
It is also possible to intercept `cpr::InterceptorMulti` calls.
1220
1246
Each interceptor implementation must inherit from the abstract class `cpr::InterceptorMulti` for intercepting `cpr::MultiPerform` objects.
1221
-
The inherited class has to implement the function `std::vector<Response> intercept(MultiPerform&)`.
1247
+
The inherited class has to implement the function `std::vector<Response> intercept(MultiPerform&)`.
1222
1248
This function is automatically called for every added interceptor during the request with the session object belonging to the request passed as a parameter.
1223
1249
An essential point of the intercept function is that it must call the `std::vector<Response> proceed()` for `cpr::InterceptorMulti`) function implemented in `cpr::Interceptor` (`cpr::InterceptorMulti`). This is necessary to continue the request and get the `cpr::Response` (`std::vector<Response>`) object.
1224
1250
@@ -1338,7 +1364,7 @@ It is possible to specify which IP address should a specific domain name and por
0 commit comments