diff --git a/client_http.hpp b/client_http.hpp index fcc47dd..be8d023 100644 --- a/client_http.hpp +++ b/client_http.hpp @@ -62,9 +62,11 @@ namespace SimpleWeb { /// Convenience function to return std::string. The stream buffer is consumed. std::string string() noexcept { try { - std::stringstream ss; - ss << rdbuf(); - return ss.str(); + std::string str; + auto size = streambuf.size(); + str.resize(size); + read(&str[0], static_cast(size)); + return str; } catch(...) { return std::string(); diff --git a/server_http.hpp b/server_http.hpp index e282bcb..235dcb8 100644 --- a/server_http.hpp +++ b/server_http.hpp @@ -163,9 +163,11 @@ namespace SimpleWeb { /// Convenience function to return std::string. The stream buffer is consumed. std::string string() noexcept { try { - std::stringstream ss; - ss << rdbuf(); - return ss.str(); + std::string str; + auto size = streambuf.size(); + str.resize(size); + read(&str[0], static_cast(size)); + return str; } catch(...) { return std::string();