Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: apply suggestions from code review comments
Browse files Browse the repository at this point in the history
sjinks committed Nov 19, 2024

Verified

This commit was signed with the committer’s verified signature.
sjinks Volodymyr Kolesnykov
1 parent 478139d commit c872a71
Showing 1 changed file with 18 additions and 29 deletions.
47 changes: 18 additions & 29 deletions ext/include/opentelemetry/ext/http/common/url_parser.h
Original file line number Diff line number Diff line change
@@ -51,8 +51,7 @@ class UrlParser
}
else
{
scheme_ = std::string(url_.begin() + static_cast<std::string::difference_type>(cpos),
url_.begin() + static_cast<std::string::difference_type>(pos));
scheme_ = url_.substr(cpos, pos - cpos);
cpos = pos + 3;
}

@@ -74,16 +73,19 @@ class UrlParser
{
// port missing. Used default 80 / 443
if (scheme_ == "http")
{
port_ = 80;
if (scheme_ == "https")
}
else if (scheme_ == "https")
{
port_ = 443;
}
}
else
{
// port present
is_port = true;
host_ = std::string(url_.begin() + static_cast<std::string::difference_type>(cpos),
url_.begin() + static_cast<std::string::difference_type>(pos));
host_ = url_.substr(cpos, pos - cpos);
cpos = pos + 1;
}
pos = url_.find_first_of("/?", cpos);
@@ -92,30 +94,23 @@ class UrlParser
path_ = std::string("/"); // use default path
if (is_port)
{
std::string port_str(
url_.begin() + static_cast<std::string::difference_type>(cpos),
url_.begin() + static_cast<std::string::difference_type>(url_.length()));

port_ = GetPort(port_str);
auto port_str = url_.substr(cpos, url_.length());
port_ = GetPort(port_str);
}
else
{
host_ =
std::string(url_.begin() + static_cast<std::string::difference_type>(cpos),
url_.begin() + static_cast<std::string::difference_type>(url_.length()));
host_ = url_.substr(cpos, url_.length());
}
return;
}
if (is_port)
{
std::string port_str(url_.begin() + static_cast<std::string::difference_type>(cpos),
url_.begin() + static_cast<std::string::difference_type>(pos));
port_ = GetPort(port_str);
auto port_str = url_.substr(cpos, pos - cpos);
port_ = GetPort(port_str);
}
else
{
host_ = std::string(url_.begin() + static_cast<std::string::difference_type>(cpos),
url_.begin() + static_cast<std::string::difference_type>(pos));
host_ = url_.substr(cpos, pos - cpos);
}
cpos = pos;

@@ -124,27 +119,21 @@ class UrlParser
pos = url_.find('?', cpos);
if (pos == std::string::npos)
{
path_ =
std::string(url_.begin() + static_cast<std::string::difference_type>(cpos),
url_.begin() + static_cast<std::string::difference_type>(url_.length()));
path_ = url_.substr(cpos, url_.length() - cpos);
query_ = "";
}
else
{
path_ = std::string(url_.begin() + static_cast<std::string::difference_type>(cpos),
url_.begin() + static_cast<std::string::difference_type>(pos));
cpos = pos + 1;
query_ =
std::string(url_.begin() + static_cast<std::string::difference_type>(cpos),
url_.begin() + static_cast<std::string::difference_type>(url_.length()));
path_ = url_.substr(cpos, pos - cpos);
cpos = pos + 1;
query_ = url_.substr(cpos, url_.length() - cpos);
}
return;
}
path_ = std::string("/");
if (url_[cpos] == '?')
{
query_ = std::string(url_.begin() + static_cast<std::string::difference_type>(cpos),
url_.begin() + static_cast<std::string::difference_type>(url_.length()));
query_ = url_.substr(cpos, url_.length() - cpos);
}
}

0 comments on commit c872a71

Please sign in to comment.