diff --git a/client_http.hpp b/client_http.hpp index b4da323..5e92df0 100644 --- a/client_http.hpp +++ b/client_http.hpp @@ -29,22 +29,6 @@ namespace SimpleWeb { } // namespace SimpleWeb #endif -#if __cplusplus > 201402L || (defined(_MSC_VER) && _MSC_VER >= 1910) -#include -namespace SimpleWeb { - using string_view = std::string_view; -} -#elif !defined(USE_STANDALONE_ASIO) -#include -namespace SimpleWeb { - using string_view = boost::string_ref; -} -#else -namespace SimpleWeb { - using string_view = const std::string &; -} -#endif - namespace SimpleWeb { template class Client; diff --git a/http_examples.cpp b/http_examples.cpp index 3e16a9c..b19985a 100644 --- a/http_examples.cpp +++ b/http_examples.cpp @@ -108,7 +108,7 @@ int main() { // GET-example for the path /match/[number], responds with the matched string in path (number) // For instance a request GET /match/123 will receive: 123 server.resource["^/match/([0-9]+)$"]["GET"] = [](shared_ptr response, shared_ptr request) { - response->write(request->path_match[1]); + response->write(request->path_match[1].str()); }; // GET-example simulating heavy work in a separate thread diff --git a/https_examples.cpp b/https_examples.cpp index 7f8794a..30bd517 100644 --- a/https_examples.cpp +++ b/https_examples.cpp @@ -106,7 +106,7 @@ int main() { // GET-example for the path /match/[number], responds with the matched string in path (number) // For instance a request GET /match/123 will receive: 123 server.resource["^/match/([0-9]+)$"]["GET"] = [](shared_ptr response, shared_ptr request) { - response->write(request->path_match[1]); + response->write(request->path_match[1].str()); }; // GET-example simulating heavy work in a separate thread diff --git a/server_http.hpp b/server_http.hpp index fd0703c..84b410b 100644 --- a/server_http.hpp +++ b/server_http.hpp @@ -161,7 +161,7 @@ namespace SimpleWeb { } /// Convenience function for writing status line, header fields, and content - void write(StatusCode status_code, const std::string &content, const CaseInsensitiveMultimap &header = CaseInsensitiveMultimap()) { + void write(StatusCode status_code, string_view content, const CaseInsensitiveMultimap &header = CaseInsensitiveMultimap()) { *this << "HTTP/1.1 " << SimpleWeb::status_code(status_code) << "\r\n"; write_header(header, content.size()); if(!content.empty()) @@ -180,7 +180,7 @@ namespace SimpleWeb { } /// Convenience function for writing success status line, header fields, and content - void write(const std::string &content, const CaseInsensitiveMultimap &header = CaseInsensitiveMultimap()) { + void write(string_view content, const CaseInsensitiveMultimap &header = CaseInsensitiveMultimap()) { write(StatusCode::success_ok, content, header); } diff --git a/utility.hpp b/utility.hpp index 2c0d146..c4ade09 100644 --- a/utility.hpp +++ b/utility.hpp @@ -8,6 +8,22 @@ #include #include +#if __cplusplus > 201402L || (defined(_MSC_VER) && _MSC_VER >= 1910) +#include +namespace SimpleWeb { + using string_view = std::string_view; +} +#elif !defined(USE_STANDALONE_ASIO) +#include +namespace SimpleWeb { + using string_view = boost::string_ref; +} +#else +namespace SimpleWeb { + using string_view = const std::string &; +} +#endif + namespace SimpleWeb { inline bool case_insensitive_equal(const std::string &str1, const std::string &str2) noexcept { return str1.size() == str2.size() &&