diff --git a/common/stream_uri.cpp b/common/stream_uri.cpp index a431bdb5..75ad76ad 100644 --- a/common/stream_uri.cpp +++ b/common/stream_uri.cpp @@ -74,6 +74,15 @@ void StreamUri::parse(const std::string& stream_uri) tmp = tmp.substr(2); // tmp = [user:password@]host[:port][/]path[?query][#fragment] + pos = tmp.find('@'); + if (pos != std::string::npos) + { + user = tmp.substr(0, pos); + if (user.find(':') != std::string::npos) + user = strutils::split_left(user, ':', password); + tmp = tmp.substr(pos + 1); + } + pos = tmp.find('/'); if (pos == string::npos) { diff --git a/common/stream_uri.hpp b/common/stream_uri.hpp index ebeb94bd..5cfb2ae5 100644 --- a/common/stream_uri.hpp +++ b/common/stream_uri.hpp @@ -43,6 +43,12 @@ struct StreamUri std::string uri; /// the scheme component (pipe, http, file, tcp, ...) std::string scheme; + + /// user name + std::string user; + /// password + std::string password; + // struct Authority // { // std::string username; diff --git a/test/test_main.cpp b/test/test_main.cpp index 59f8375a..56c26eb0 100644 --- a/test/test_main.cpp +++ b/test/test_main.cpp @@ -225,6 +225,22 @@ TEST_CASE("Uri") REQUIRE(uri.path == "/tmp/snapfifo"); REQUIRE(uri.host.empty()); + uri = StreamUri("wss://user:pass@localhost:1788"); + REQUIRE(uri.scheme == "wss"); + REQUIRE(uri.path.empty()); + REQUIRE(uri.host == "localhost"); + REQUIRE(uri.user == "user"); + REQUIRE(uri.password == "pass"); + REQUIRE(uri.port == 1788); + + uri = StreamUri("wss://user@localhost:1788"); + REQUIRE(uri.scheme == "wss"); + REQUIRE(uri.path.empty()); + REQUIRE(uri.host == "localhost"); + REQUIRE(uri.user == "user"); + REQUIRE(uri.password.empty()); + REQUIRE(uri.port == 1788); + // uri = StreamUri("scheme:[//host[:port]][/]path[?query=none][#fragment]"); // Test with all fields uri = StreamUri("scheme://host:42/path?query=none&key=value#fragment");