22#define INCLUDE_CCAPI_CPP_CCAPI_WS_CONNECTION_H_
33
44#include < string>
5+ #include < variant>
56
67#include " ccapi_cpp/ccapi_logger.h"
78#include " ccapi_cpp/ccapi_subscription.h"
@@ -16,9 +17,9 @@ class WsConnection {
1617 WsConnection (const WsConnection&) = delete ;
1718 WsConnection& operator =(const WsConnection&) = delete ;
1819
19- WsConnection (std::string url, std::string group, std::vector<Subscription> subscriptionList, std::map<std::string, std::string> credential ,
20- std::shared_ptr<beast::websocket::stream<beast::ssl_stream<beast::tcp_stream>>> streamPtr )
21- : url(url), group(group), subscriptionList(subscriptionList), credential(credential), streamPtr(streamPtr) {
20+ WsConnection (const std::string& url, const std::string& group, const std::vector<Subscription>& subscriptionList,
21+ const std::map<std::string, std::string>& credential )
22+ : url(url), group(group), subscriptionList(subscriptionList), credential(credential) {
2223 std::map<std::string, std::string> shortCredential;
2324 for (const auto & x : credential) {
2425 shortCredential.insert (std::make_pair (x.first , UtilString::firstNCharacter (x.second , CCAPI_CREDENTIAL_DISPLAY_LENGTH )));
@@ -39,7 +40,15 @@ class WsConnection {
3940 shortCredential.insert (std::make_pair (x.first , UtilString::firstNCharacter (x.second , CCAPI_CREDENTIAL_DISPLAY_LENGTH )));
4041 }
4142 std::ostringstream oss;
42- oss << streamPtr;
43+ std::visit (
44+ [&oss](auto && streamSharedPtr) {
45+ if (streamSharedPtr) {
46+ oss << streamSharedPtr.get ();
47+ } else {
48+ oss << " nullptr" ;
49+ }
50+ },
51+ streamPtr);
4352 std::string output = " WsConnection [longId = " + longId + " , id = " + id + " , url = " + url + " , group = " + group +
4453 " , subscriptionList = " + ccapi::toString (subscriptionList) + " , credential = " + ccapi::toString (shortCredential) +
4554 " , status = " + statusToString (status) + " , headers = " + ccapi::toString (headers) + " , streamPtr = " + oss.str () +
@@ -116,6 +125,9 @@ class WsConnection {
116125 this ->port = CCAPI_HTTP_PORT_DEFAULT ;
117126 }
118127 }
128+ if (splitted1.at (0 ) == " https" || splitted1.at (0 ) == " wss" ) {
129+ this ->isSecure = true ;
130+ }
119131 }
120132 }
121133
@@ -133,7 +145,8 @@ class WsConnection {
133145 Status status{Status::UNKNOWN };
134146 std::map<std::string, std::string> headers;
135147 std::map<std::string, std::string> credential;
136- std::shared_ptr<beast::websocket::stream<beast::ssl_stream<beast::tcp_stream>>> streamPtr;
148+ std::variant<std::shared_ptr<beast::websocket::stream<beast::ssl_stream<beast::tcp_stream>>>, std::shared_ptr<beast::websocket::stream<beast::tcp_stream>>>
149+ streamPtr;
137150 beast::websocket::close_code remoteCloseCode{};
138151 beast::websocket::close_reason remoteCloseReason{};
139152 std::string hostHttpHeaderValue;
@@ -145,6 +158,7 @@ class WsConnection {
145158 std::array<char , CCAPI_WEBSOCKET_WRITE_BUFFER_SIZE > writeMessageBuffer;
146159 size_t writeMessageBufferWrittenLength{};
147160 std::vector<size_t > writeMessageBufferBoundary;
161+ bool isSecure{};
148162};
149163
150164} /* namespace ccapi */
0 commit comments