oatpp / oatpp

🌱Light and powerful C++ web framework for highly scalable and resource-efficient web application. It's zero-dependency and easy-portable.
https://oatpp.io/
Apache License 2.0
7.94k stars 1.31k forks source link

guarantee reading of request body in persistent connection #675

Open DanielHerchenbach opened 1 year ago

DanielHerchenbach commented 1 year ago

Hello, let's say reading the body of a request is omitted because the endpoint definition contains something like: if (acceptFileTransfer) { request->transferBodyToStream(&fileOutputStream); } else { // body not read! } Maybe I am missing something but I guess in the else branch, the stream position is not moved to the end of the body. This is a problem for the next request on the same connection (if any) because its headers are then parsed starting from the previous body section.

lganzzzo commented 1 year ago

Hello @DanielHerchenbach ,

You are correct. It's a known issue.

Also, it's planned for the next release.

Just for the reference:

ns-wxin commented 3 months ago

I noticed this bug is still open. The workaround posted on stack exchange wasn't clear on what condition it would leave the body uncleared. Does a "persisted connection" mean any endpoint called prior to the errored endpoint would need to drain the body? or just the same endpoint with POST/PUT/DELETE that needs to drain the body? Do I need to drain the body on GET? If my service has 20+ endpoints, do I need to drain the body for all of them?

Also, just found out the suggested workaround on stack exchange doesn't work if there's no payload. [oatpp::web::protocol::http::incoming::SimpleBodyDecoder::decode()]: Error. Invalid Request.

I don't know if client would provide request body or not.