Skip to content
Snippets Groups Projects
Commit 87f6f3df authored by Seva's avatar Seva
Browse files

http: fix & test url with https but empty service

parent 7270c353
No related branches found
No related tags found
No related merge requests found
...@@ -43,8 +43,10 @@ Url::Url(const std::string& url): url(url) ...@@ -43,8 +43,10 @@ Url::Url(const std::string& url): url(url)
const size_t proto_end = url.find("://"); const size_t proto_end = url.find("://");
if (proto_end != std::string::npos){ if (proto_end != std::string::npos){
addr_begin = proto_end + 3; addr_begin = proto_end + 3;
if (url.substr(0, proto_end) == "https") if (url.substr(0, proto_end) == "https"){
protocol = "https"; protocol = "https";
service = protocol;
}
} }
// host and service // host and service
size_t addr_size = url.substr(addr_begin).find("/"); size_t addr_size = url.substr(addr_begin).find("/");
......
...@@ -53,6 +53,20 @@ HttpTester::test_parse_url() { ...@@ -53,6 +53,20 @@ HttpTester::test_parse_url() {
CPPUNIT_ASSERT(parsed.target == "/"); CPPUNIT_ASSERT(parsed.target == "/");
} }
void
HttpTester::test_parse_https_url_no_service() {
// Arrange
std::string url = "https://jami.net/";
// Act
dht::http::Url parsed (url);
// Assert
CPPUNIT_ASSERT(parsed.url == url);
CPPUNIT_ASSERT(parsed.protocol == "https");
CPPUNIT_ASSERT(parsed.host == "jami.net");
CPPUNIT_ASSERT(parsed.service == "https");
CPPUNIT_ASSERT(parsed.target == "/");
}
void void
HttpTester::test_parse_url_no_prefix_no_target() { HttpTester::test_parse_url_no_prefix_no_target() {
// Arrange // Arrange
......
...@@ -31,6 +31,7 @@ namespace test { ...@@ -31,6 +31,7 @@ namespace test {
class HttpTester : public CppUnit::TestFixture { class HttpTester : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(HttpTester); CPPUNIT_TEST_SUITE(HttpTester);
CPPUNIT_TEST(test_parse_url); CPPUNIT_TEST(test_parse_url);
CPPUNIT_TEST(test_parse_https_url_no_service);
CPPUNIT_TEST(test_parse_url_no_prefix_no_target); CPPUNIT_TEST(test_parse_url_no_prefix_no_target);
CPPUNIT_TEST(test_parse_url_target); CPPUNIT_TEST(test_parse_url_target);
CPPUNIT_TEST(test_parse_url_query); CPPUNIT_TEST(test_parse_url_query);
...@@ -57,6 +58,7 @@ class HttpTester : public CppUnit::TestFixture { ...@@ -57,6 +58,7 @@ class HttpTester : public CppUnit::TestFixture {
* Test parse urls * Test parse urls
*/ */
void test_parse_url(); void test_parse_url();
void test_parse_https_url_no_service();
void test_parse_url_no_prefix_no_target(); void test_parse_url_no_prefix_no_target();
void test_parse_url_target(); void test_parse_url_target();
void test_parse_url_query(); void test_parse_url_query();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment