Allow Clearing Session Content Via E.G. `cpr::Session::ClearContent();`
Description
I'm using a cpr::Session to perform multiple HTTP Requests.
At first I want to do a HTTP POST with a multipart parameter.
After that I want to do a simple GET.
It seems like cpr always performs a POST when a multipart parameter has been added to the session.
This is because the sessions prepareCommon adds the content to each request once it was set for the session.
cpr::Session session;
session.SetUrl( ... );
session.SetMultipart( ... );
session.Post( );
session.Get( ); <-- This is also a POST
Is this the desired beaviour? Is there any workaround to remove the content from the session after the POST?
Example/How to Reproduce
- Create a
cpr::Session - Set Mulipart parameter
- Perform POST
- Perform GET
Possible Fix
No response
Where did you get it from?
GitHub (branch e.g. master)
Additional Context/Your Environment
- OS: Linux
- Version: 1.11.0
@DanielRe1 thanks for reporting!
Sadly there is no way right now to clear the underlying std::variant<std::monostate, cpr::Payload, cpr::Body, cpr::Multipart> content_{std::monostate{}}; object back to std::monostate{}.
But what you could try is:
session.SetBody(cpr::Body{});
That way you at least clear the multipart.
Is this intended behaviour?
I'd say right now yes. But I would be open to merging a MR that adds a cpr::Session::ClearContent(); (or called differently) call to session.