Skip to content

Commit 601f444

Browse files
jimmy-parkzkx
authored and
zkx
committed
Support move semantics for Response::set_content() (yhirose#1764)
(cherry picked from commit 44b3fe6)
1 parent 8e7f82f commit 601f444

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

httplib.h

+10
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,7 @@ struct Response {
597597
void set_redirect(const std::string &url, int status = StatusCode::Found_302);
598598
void set_content(const char *s, size_t n, const std::string &content_type);
599599
void set_content(const std::string &s, const std::string &content_type);
600+
void set_content(std::string &&s, const std::string &content_type);
600601

601602
void set_content_provider(
602603
size_t length, const std::string &content_type, ContentProvider provider,
@@ -5349,6 +5350,15 @@ inline void Response::set_content(const std::string &s,
53495350
set_content(s.data(), s.size(), content_type);
53505351
}
53515352

5353+
inline void Response::set_content(std::string &&s,
5354+
const std::string &content_type) {
5355+
body = std::move(s);
5356+
5357+
auto rng = headers.equal_range("Content-Type");
5358+
headers.erase(rng.first, rng.second);
5359+
set_header("Content-Type", content_type);
5360+
}
5361+
53525362
inline void Response::set_content_provider(
53535363
size_t in_length, const std::string &content_type, ContentProvider provider,
53545364
ContentProviderResourceReleaser resource_releaser) {

0 commit comments

Comments
 (0)