Skip to content

Commit

Permalink
Support move semantics for Response::set_content() (yhirose#1764)
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmy-park authored Jan 27, 2024
1 parent 4498019 commit 44b3fe6
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions httplib.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 44b3fe6

Please sign in to comment.