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
Even the most trivial use of AddInterceptor leads only to interceptors being called for a single request. Unfortunately the current implementation drops interceptors from the queue once they are called, see Session::intercept(). My understanding of the purpose of having a Session object is to being able to perform multiple calls to e.g. Get() and thus my assumption was that all added interceptors stay active for the session lifetime and are called for any number of Get() calls.
I was trying to implement some resilience policies, retry mainly, as the documentation states "...which can then monitor, modify and repeat requests". I was assuming that intercept() could call proceed() multiple times to repeat requests, but that was a non-starter.
Example/How to Reproduce
class LogInterceptor : public cpr::Interceptor
{
public:
cpr::Response intercept(cpr::Session& session) override
{
auto r = proceed(session);
std::cout << "In LogInterceptor" << std::endl;
return r;
}
};
void main()
{
cpr::Session session;
session.SetUrl("https://httpstat.us/200");
session.AddInterceptor(std::make_shared<LogInterceptor>());
auto r = session.Get();
// This is required to get the interceptor also called during next Get()
// session.AddInterceptor(std::make_shared<LogInterceptor>());
r = session.Get();
}
Possible Fix
To fix the simple case of keeping interceptors active for any number of requests you may "just" not pop interceptors out of the queue and instead iterate over them.
To implement the promised "can repeat requests" fully (calling all interceptors) it may require quite some effort. Maybe calling only down-level interceptors in repeated requests should-just-work (TM) if fixing the above.
Where did you get it from?
vcpkg
Additional Context/Your Environment
OS: Windows 11
Version: 1.10.5
The text was updated successfully, but these errors were encountered:
Description
Even the most trivial use of AddInterceptor leads only to interceptors being called for a single request. Unfortunately the current implementation drops interceptors from the queue once they are called, see Session::intercept(). My understanding of the purpose of having a Session object is to being able to perform multiple calls to e.g. Get() and thus my assumption was that all added interceptors stay active for the session lifetime and are called for any number of Get() calls.
I was trying to implement some resilience policies, retry mainly, as the documentation states "...which can then monitor, modify and repeat requests". I was assuming that intercept() could call proceed() multiple times to repeat requests, but that was a non-starter.
Example/How to Reproduce
Possible Fix
To fix the simple case of keeping interceptors active for any number of requests you may "just" not pop interceptors out of the queue and instead iterate over them.
To implement the promised "can repeat requests" fully (calling all interceptors) it may require quite some effort. Maybe calling only down-level interceptors in repeated requests should-just-work (TM) if fixing the above.
Where did you get it from?
vcpkg
Additional Context/Your Environment
The text was updated successfully, but these errors were encountered: