Add toString for drogon::ReqResult (#1133)

* Add to_string and to_string_view for drogon::ReqResult
This commit is contained in:
Ichiro 2021-12-24 21:45:36 +09:00 committed by GitHub
parent bc4e8faec2
commit 6c8f8bac1f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -15,6 +15,8 @@
#include <atomic>
#include <thread>
#include <iostream>
#include <drogon/utils/string_view.h>
#include <trantor/utils/LogStream.h>
namespace drogon
{
@ -169,26 +171,43 @@ enum class WebSocketMessageType
Close,
Unknown
};
inline std::ostream &operator<<(std::ostream &out, drogon::ReqResult result)
inline string_view to_string_view(drogon::ReqResult result)
{
switch (result)
{
case ReqResult::Ok:
return out << "OK";
return "OK";
case ReqResult::BadResponse:
return out << "Bad response from server";
return "Bad response from server";
case ReqResult::NetworkFailure:
return out << "Network failure";
return "Network failure";
case ReqResult::BadServerAddress:
return out << "Bad server address";
return "Bad server address";
case ReqResult::Timeout:
return out << "Timeout";
return "Timeout";
case ReqResult::HandshakeError:
return out << "Handshake error";
return "Handshake error";
case ReqResult::InvalidCertificate:
return out << "Invalid certificate";
return "Invalid certificate";
default:
return out << "Unknown error";
return "Unknown error";
}
}
inline std::string to_string(drogon::ReqResult result)
{
return to_string_view(result).data();
}
inline std::ostream &operator<<(std::ostream &out, drogon::ReqResult result)
{
return out << to_string_view(result);
}
inline trantor::LogStream &operator<<(trantor::LogStream &out,
drogon::ReqResult result)
{
return out << to_string_view(result);
}
} // namespace drogon