diff --git a/include/frnetlib/URL.h b/include/frnetlib/URL.h index a1d69c5..9b762b5 100644 --- a/include/frnetlib/URL.h +++ b/include/frnetlib/URL.h @@ -124,6 +124,16 @@ namespace fr */ static const std::string &scheme_to_string(Scheme scheme); + /*! + * Comparison operator + * + * @param o Object to compare against + * @return True if equal, false otherwise + */ + inline bool operator==(const URL &o) const + { + return scheme == o.scheme && host == o.host && port == o.port && path == o.path && query == o.query && fragment == o.fragment; + } private: /*! * Converts a string to lower case diff --git a/src/SSLListener.cpp b/src/SSLListener.cpp index 13fe2fc..d46cd9f 100644 --- a/src/SSLListener.cpp +++ b/src/SSLListener.cpp @@ -30,14 +30,14 @@ namespace fr error = mbedtls_x509_crt_parse_file(&srvcert, pem_path.c_str()); if(error != 0) { - throw std::runtime_error("mbedtls_x509_crt_parse_file() returned: " + std::to_string(error)); + throw std::runtime_error("Error parsing '" + pem_path + "': mbedtls_x509_crt_parse_file() returned " + std::to_string(error)); } //Load private key error = mbedtls_pk_parse_keyfile(&pkey, private_key_path.c_str(), 0); if(error != 0) { - throw std::runtime_error("mbedtls_pk_parse_keyfile() returned: " + std::to_string(error)); + throw std::runtime_error("Error parsing '" + private_key_path + "': mbedtls_pk_parse_keyfile() returned " + std::to_string(error)); } //Setup data structures and apply settings diff --git a/src/URL.cpp b/src/URL.cpp index 7bdae48..d1daaa4 100644 --- a/src/URL.cpp +++ b/src/URL.cpp @@ -21,7 +21,6 @@ namespace fr }; URL::URL(const std::string &url) - : scheme(Scheme::Unknown) { parse(url); } @@ -29,6 +28,7 @@ namespace fr void URL::parse(std::string url) { + scheme = Scheme::Unknown; size_t parse_offset = 0; size_t pos = 0; diff --git a/tests/URLTest.cpp b/tests/URLTest.cpp index 1563479..3948041 100644 --- a/tests/URLTest.cpp +++ b/tests/URLTest.cpp @@ -64,4 +64,12 @@ TEST(URLTest, uri_test4) { fr::URL url("http://example.com:80/?bob=10#frag"); ASSERT_EQ(url.get_uri(), "/?bob=10#frag"); +} + +TEST(URLTest, schema_parse_test) +{ + fr::URL url("127.0.0.1:2020"); + fr::URL url2; + url2.parse("127.0.0.1:2020"); + ASSERT_EQ(url, url2); } \ No newline at end of file