Skip to content

Commit af60e01

Browse files
committed
add getUrl method
1 parent 6eee4c6 commit af60e01

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/WebSocketsClient.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,19 @@ bool WebSocketsClient::isConnected(void) {
478478
return (_client.status == WSC_CONNECTED);
479479
}
480480

481+
/**
482+
* RFC 6455
483+
* get the full URL/URI of the connection
484+
*/
485+
String WebSocketsClient::getUrl(void) {
486+
#if defined(HAS_SSL)
487+
String protocol = (_client.isSSL) ? WEBSOCKETS_STRING("wss://") : WEBSOCKETS_STRING("ws://");
488+
#else
489+
String protocol = WEBSOCKETS_STRING("ws://");
490+
#endif
491+
return protocol + _host + ":" + String(_port) + _client.cUrl;
492+
}
493+
481494
// #################################################################################
482495
// #################################################################################
483496
// #################################################################################

src/WebSocketsClient.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ class WebSocketsClient : protected WebSockets {
112112
void disableHeartbeat();
113113

114114
bool isConnected(void);
115+
String getUrl(void);
115116

116117
protected:
117118
String _host;

0 commit comments

Comments
 (0)