Skip to content

Commit 698a1e5

Browse files
db-srcDaniel Boles
andauthored
Move, not copy, Logger and Handler functors (#1576)
* Explicitly #include <utility> for use of std::move * Move not copy Logger arg from Client to ClientImpl * Move not copy, set_error_handler Handler to lambda * Remove null statement in non-empty if/else block I guess it was a relic from a time before the other statement was added. --------- Co-authored-by: Daniel Boles <[email protected]>
1 parent 27c0e11 commit 698a1e5

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

httplib.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ using socket_t = int;
223223
#include <string>
224224
#include <sys/stat.h>
225225
#include <thread>
226+
#include <utility>
226227

227228
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
228229
#ifdef _WIN32
@@ -5242,7 +5243,7 @@ inline Server &Server::set_error_handler(HandlerWithResponse handler) {
52425243
}
52435244

52445245
inline Server &Server::set_error_handler(Handler handler) {
5245-
error_handler_ = [handler](const Request &req, Response &res) {
5246+
error_handler_ = [handler = std::move(handler)](const Request &req, Response &res) {
52465247
handler(req, res);
52475248
return HandlerResponse::Handled;
52485249
};
@@ -5272,7 +5273,6 @@ inline Server &Server::set_logger(Logger logger) {
52725273
inline Server &
52735274
Server::set_expect_100_continue_handler(Expect100ContinueHandler handler) {
52745275
expect_100_continue_handler_ = std::move(handler);
5275-
52765276
return *this;
52775277
}
52785278

@@ -6801,7 +6801,6 @@ inline std::unique_ptr<Response> ClientImpl::send_with_content_provider(
68016801
req.set_header("Transfer-Encoding", "chunked");
68026802
} else {
68036803
req.body.assign(body, content_length);
6804-
;
68056804
}
68066805
}
68076806

@@ -8750,7 +8749,9 @@ inline void Client::enable_server_certificate_verification(bool enabled) {
87508749
}
87518750
#endif
87528751

8753-
inline void Client::set_logger(Logger logger) { cli_->set_logger(logger); }
8752+
inline void Client::set_logger(Logger logger) {
8753+
cli_->set_logger(std::move(logger));
8754+
}
87548755

87558756
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
87568757
inline void Client::set_ca_cert_path(const std::string &ca_cert_file_path,

0 commit comments

Comments
 (0)