diff --git a/components/common/cpp/include/ftl/uri.hpp b/components/common/cpp/include/ftl/uri.hpp index 71e3bf456082f73a3ec98b397a217beaf8cdb41a..7f549f66a4a8fccd5b8b9eb098088ba604edb3f3 100644 --- a/components/common/cpp/include/ftl/uri.hpp +++ b/components/common/cpp/include/ftl/uri.hpp @@ -53,6 +53,8 @@ namespace ftl { */ std::string getBaseURI(int n); + std::string getBaseURIWithUser(); + std::string getPathSegment(int n) const; void setAttribute(const std::string &key, const std::string &value); diff --git a/components/common/cpp/src/configuration.cpp b/components/common/cpp/src/configuration.cpp index 790cb2b960189aa21f0c2f0944aeb66b07cfe175..e987b6afac423cc0d35f11d4501bc5f81e4737ac 100644 --- a/components/common/cpp/src/configuration.cpp +++ b/components/common/cpp/src/configuration.cpp @@ -30,6 +30,7 @@ #include <string> #include <map> #include <iostream> +#include <iomanip> using ftl::config::json_t; using std::ifstream; @@ -201,7 +202,7 @@ bool ftl::saveJSON(const std::string &path, nlohmann::json &json) { //i.open(path); if (o.is_open()) { try { - o << json; + o << std::setw(4) << json << std::endl; return true; } catch (...) { LOG(ERROR) << "Unknown error saving JSON file: " << path; diff --git a/components/common/cpp/src/uri.cpp b/components/common/cpp/src/uri.cpp index 768e6a6126bf9a23b45ef84ca6183d6f81e42ce5..37a5d579215faecbb3fa0be36391ed986e6e52f1 100644 --- a/components/common/cpp/src/uri.cpp +++ b/components/common/cpp/src/uri.cpp @@ -182,6 +182,20 @@ string URI::getBaseURI(int n) { } else return ""; } +std::string URI::getBaseURIWithUser() { + std::string result; + + result += m_protostr + "://"; + if (m_userinfo.size() > 0) { + result += getUserInfo(); + result += "@"; + } + result += m_host; + if (m_port > 0) result += std::string(":") + std::to_string(m_port); + result += m_path; + return result; +} + string URI::getQuery() const { string q; for (auto x : m_qmap) { diff --git a/components/common/cpp/test/uri_unit.cpp b/components/common/cpp/test/uri_unit.cpp index 59c5391f35f93050b42a6df8835de6b7ab22adfc..b41cb9a017f41310d90ad7855adb0f20d4d70d46 100644 --- a/components/common/cpp/test/uri_unit.cpp +++ b/components/common/cpp/test/uri_unit.cpp @@ -189,3 +189,15 @@ SCENARIO( "URI::getBaseURI(N)" ) { } } +SCENARIO( "URI::getBaseURIWithUser()" ) { + GIVEN( "both username and password" ) { + URI uri("http://nick:test@localhost:1000/hello/world?group=test2"); + REQUIRE( uri.getBaseURIWithUser() == "http://nick:test@localhost:1000/hello/world" ); + } + + GIVEN( "missing username and password" ) { + URI uri("http://localhost:1000/hello/world?group=test2"); + REQUIRE( uri.getBaseURIWithUser() == "http://localhost:1000/hello/world" ); + } +} + diff --git a/components/streams/src/feed.cpp b/components/streams/src/feed.cpp index 7a2fedd0dc428a8914a131b42a6fbfce01f2cb75..7dad368a14ee4828fe96ebbaf03f5cb5c50c355c 100644 --- a/components/streams/src/feed.cpp +++ b/components/streams/src/feed.cpp @@ -671,7 +671,7 @@ uint32_t Feed::add(const std::string &path) { // TODO: write unit test auto &known_hosts = getConfig()["known_hosts"]; - auto &host_details = known_hosts[uri.getBaseURI()]; + auto &host_details = known_hosts[uri.getBaseURIWithUser()]; host_details["last_open"] = ftl::timer::get_time(); net_->connect(path)->waitConnection();