mirror of
https://gitee.com/an-tao/drogon.git
synced 2024-12-02 11:47:56 +08:00
Add toString for drogon::ReqResult
(#1133)
* Add to_string and to_string_view for drogon::ReqResult
This commit is contained in:
parent
bc4e8faec2
commit
6c8f8bac1f
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user