Skip to content

Commit

Permalink
Move, not copy, Logger and Handler functors (#1576)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
db-src and Daniel Boles authored Jun 2, 2023
1 parent 27c0e11 commit 698a1e5
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions httplib.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ using socket_t = int;
#include <string>
#include <sys/stat.h>
#include <thread>
#include <utility>

#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
#ifdef _WIN32
Expand Down Expand Up @@ -5242,7 +5243,7 @@ inline Server &Server::set_error_handler(HandlerWithResponse handler) {
}

inline Server &Server::set_error_handler(Handler handler) {
error_handler_ = [handler](const Request &req, Response &res) {
error_handler_ = [handler = std::move(handler)](const Request &req, Response &res) {
handler(req, res);
return HandlerResponse::Handled;
};
Expand Down Expand Up @@ -5272,7 +5273,6 @@ inline Server &Server::set_logger(Logger logger) {
inline Server &
Server::set_expect_100_continue_handler(Expect100ContinueHandler handler) {
expect_100_continue_handler_ = std::move(handler);

return *this;
}

Expand Down Expand Up @@ -6801,7 +6801,6 @@ inline std::unique_ptr<Response> ClientImpl::send_with_content_provider(
req.set_header("Transfer-Encoding", "chunked");
} else {
req.body.assign(body, content_length);
;
}
}

Expand Down Expand Up @@ -8750,7 +8749,9 @@ inline void Client::enable_server_certificate_verification(bool enabled) {
}
#endif

inline void Client::set_logger(Logger logger) { cli_->set_logger(logger); }
inline void Client::set_logger(Logger logger) {
cli_->set_logger(std::move(logger));
}

#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
inline void Client::set_ca_cert_path(const std::string &ca_cert_file_path,
Expand Down

0 comments on commit 698a1e5

Please sign in to comment.