Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Clearing Session Content Via E.G. cpr::Session::ClearContent(); #1159

Open
DanielRe1 opened this issue Jan 10, 2025 · 1 comment
Open

Comments

@DanielRe1
Copy link

DanielRe1 commented Jan 10, 2025

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

  1. Create a cpr::Session
  2. Set Mulipart parameter
  3. Perform POST
  4. 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
@COM8
Copy link
Member

COM8 commented Jan 12, 2025

@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.

@COM8 COM8 changed the title Session with multipart parameter Allow Clearing Session Content Via E.G. cpr::Session::ClearContent(); Jan 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants