Skip to content

Using sessions, the body/payload/multipart of the previous request is sent if not replaced. #1171

@simue

Description

@simue

Description

I am using a session to send multiple sequential requests. Some are GET, some are POST.
On a GET that is sent after a POST, I see that the content_ of the first request being used as custom method, see example below.

[03/Feb/2025 22:33:14] code 501, message Unsupported method ('{"thisIsMyJsonBody": "OfThePreviousPostRequest"}GET')

I'd expect the session to either internally reset content_(maybe in makeRequest?), or if not possible, I'd expect there to be the possibility of resetting content_ explicitly.
Since content_'s default is std::monostate, I'd like to introduce a reset function, setting std::monostate.

Interestingly enough, there already is a function hasBodyOrPayload which generates a custom GET request and a comment stating GET with body is illegal. But no setter/reset for content_.

Example/How to Reproduce

  1. Create a cpr::Session
  2. Send POST
  3. Send GET (without changing content_ via its various setters)
  4. Perform the request
  5. Observe method shown in server which contains the body of the POST request.

Possible Fix

See above, I'd like to introduce a reset function for content_.

Where did you get it from?

conan

Additional Context/Your Environment

  • OS: Linux
  • Version: custom on kernel 5.15

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions