From 44b3fe6277398f424f1844295b7ae46ba5a1a35f Mon Sep 17 00:00:00 2001 From: Jiwoo Park Date: Sat, 27 Jan 2024 21:53:19 +0900 Subject: [PATCH] Support move semantics for Response::set_content() (#1764) --- httplib.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/httplib.h b/httplib.h index d04ac77..0197b2f 100644 --- a/httplib.h +++ b/httplib.h @@ -596,6 +596,7 @@ struct Response { void set_redirect(const std::string &url, int status = StatusCode::Found_302); void set_content(const char *s, size_t n, const std::string &content_type); void set_content(const std::string &s, const std::string &content_type); + void set_content(std::string &&s, const std::string &content_type); void set_content_provider( size_t length, const std::string &content_type, ContentProvider provider, @@ -5350,6 +5351,15 @@ inline void Response::set_content(const std::string &s, set_content(s.data(), s.size(), content_type); } +inline void Response::set_content(std::string &&s, + const std::string &content_type) { + body = std::move(s); + + auto rng = headers.equal_range("Content-Type"); + headers.erase(rng.first, rng.second); + set_header("Content-Type", content_type); +} + inline void Response::set_content_provider( size_t in_length, const std::string &content_type, ContentProvider provider, ContentProviderResourceReleaser resource_releaser) {