Commit 464cc74d authored by Stephane Sezer's avatar Stephane Sezer Committed by Peter Griess

Add an authority() method to folly::Uri.

Summary: facebook::strings::URL has an authority() method. Having the same thing for folly::Uri help converting users of the URL class. This method just takes username, password, host, and port, and builds a string in the form <username>:<password>@<host>:<port>.

Test Plan: None.

Reviewed By: rajat@fb.com

FB internal diff: D977450
parent a88ef0be
......@@ -92,4 +92,26 @@ Uri::Uri(StringPiece str) : port_(0) {
fragment_ = submatch(match, 4);
}
fbstring
Uri::authority() const
{
fbstring result(host());
if (port() != 0) {
result += fbstring(":") + to<fbstring>(port());
}
if (!username().empty()) {
fbstring userInformation(username());
if (!password().empty()) {
userInformation += fbstring(":") + password();
}
result = userInformation + "@" + result;
}
return result;
}
} // namespace folly
......@@ -53,6 +53,8 @@ class Uri {
const fbstring& query() const { return query_; }
const fbstring& fragment() const { return fragment_; }
fbstring authority() const;
template <class String>
String toString() const;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment