Skip to content

Commit 44b3fe6

Browse files
authored
Support move semantics for Response::set_content() (yhirose#1764)
1 parent 4498019 commit 44b3fe6

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
@@ -596,6 +596,7 @@ struct Response {
596596
void set_redirect(const std::string &url, int status = StatusCode::Found_302);
597597
void set_content(const char *s, size_t n, const std::string &content_type);
598598
void set_content(const std::string &s, const std::string &content_type);
599+
void set_content(std::string &&s, const std::string &content_type);
599600

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

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

0 commit comments

Comments
 (0)