|
12 | 12 | #include <optional> |
13 | 13 | #include <stdexcept> |
14 | 14 | #include <string> |
| 15 | +#include <string_view> |
| 16 | +#include <type_traits> |
15 | 17 | #include <utility> |
16 | 18 | #include <variant> |
17 | 19 | #include <vector> |
|
26 | 28 | #include "cpr/auth.h" |
27 | 29 | #include "cpr/bearer.h" |
28 | 30 | #include "cpr/body.h" |
| 31 | +#include "cpr/body_view.h" |
29 | 32 | #include "cpr/callback.h" |
30 | 33 | #include "cpr/connect_timeout.h" |
31 | 34 | #include "cpr/cookies.h" |
@@ -492,6 +495,7 @@ void Session::SetBody(Body&& body) { |
492 | 495 | content_ = std::move(body); |
493 | 496 | } |
494 | 497 |
|
| 498 | +// cppcheck-suppress passedByValue |
495 | 499 | void Session::SetBodyView(BodyView body) { |
496 | 500 | static_assert(std::is_trivially_copyable_v<BodyView>, "BodyView expected to be trivially copyable otherwise will need some std::move across codebase"); |
497 | 501 | content_ = body; |
@@ -983,6 +987,7 @@ void Session::prepareBodyPayloadOrMultipart() const { |
983 | 987 | } else if (std::holds_alternative<cpr::BodyView>(content_)) { |
984 | 988 | const std::string_view body = std::get<cpr::BodyView>(content_).str(); |
985 | 989 | curl_easy_setopt(curl_->handle, CURLOPT_POSTFIELDSIZE_LARGE, static_cast<curl_off_t>(body.length())); |
| 990 | + // NOLINTNEXTLINE (bugprone-suspicious-stringview-data-usage) |
986 | 991 | curl_easy_setopt(curl_->handle, CURLOPT_POSTFIELDS, body.data()); |
987 | 992 | } else if (std::holds_alternative<cpr::Multipart>(content_)) { |
988 | 993 | // Make sure, we have a empty multipart to start with: |
@@ -1070,6 +1075,7 @@ void Session::SetOption(const Redirect& redirect) { SetRedirect(redirect); } |
1070 | 1075 | void Session::SetOption(const Cookies& cookies) { SetCookies(cookies); } |
1071 | 1076 | void Session::SetOption(const Body& body) { SetBody(body); } |
1072 | 1077 | void Session::SetOption(Body&& body) { SetBody(std::move(body)); } |
| 1078 | +// cppcheck-suppress passedByValue |
1073 | 1079 | void Session::SetOption(BodyView body) { SetBodyView(body); } |
1074 | 1080 | void Session::SetOption(const LowSpeed& low_speed) { SetLowSpeed(low_speed); } |
1075 | 1081 | void Session::SetOption(const VerifySsl& verify) { SetVerifySsl(verify); } |
|
0 commit comments