URL Parse fix

This commit is contained in:
Fred Nicolson 2018-10-25 10:41:21 +01:00
parent f26225946c
commit 5aecba03ef
4 changed files with 21 additions and 3 deletions

View File

@ -124,6 +124,16 @@ namespace fr
*/ */
static const std::string &scheme_to_string(Scheme scheme); 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: private:
/*! /*!
* Converts a string to lower case * Converts a string to lower case

View File

@ -30,14 +30,14 @@ namespace fr
error = mbedtls_x509_crt_parse_file(&srvcert, pem_path.c_str()); error = mbedtls_x509_crt_parse_file(&srvcert, pem_path.c_str());
if(error != 0) 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 //Load private key
error = mbedtls_pk_parse_keyfile(&pkey, private_key_path.c_str(), 0); error = mbedtls_pk_parse_keyfile(&pkey, private_key_path.c_str(), 0);
if(error != 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 //Setup data structures and apply settings

View File

@ -21,7 +21,6 @@ namespace fr
}; };
URL::URL(const std::string &url) URL::URL(const std::string &url)
: scheme(Scheme::Unknown)
{ {
parse(url); parse(url);
} }
@ -29,6 +28,7 @@ namespace fr
void URL::parse(std::string url) void URL::parse(std::string url)
{ {
scheme = Scheme::Unknown;
size_t parse_offset = 0; size_t parse_offset = 0;
size_t pos = 0; size_t pos = 0;

View File

@ -65,3 +65,11 @@ TEST(URLTest, uri_test4)
fr::URL url("http://example.com:80/?bob=10#frag"); fr::URL url("http://example.com:80/?bob=10#frag");
ASSERT_EQ(url.get_uri(), "/?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);
}