From: Stephane Sezer Date: Mon, 23 Sep 2013 21:42:11 +0000 (-0700) Subject: Add an authority() method to folly::Uri. X-Git-Tag: v0.22.0~868 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=464cc74d12be1772fb4846bf9a3c19b37024f6a7;p=folly.git 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 :@:. Test Plan: None. Reviewed By: rajat@fb.com FB internal diff: D977450 --- diff --git a/folly/Uri.cpp b/folly/Uri.cpp index a94c9308..c2bd85a2 100644 --- a/folly/Uri.cpp +++ b/folly/Uri.cpp @@ -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(port()); + } + + if (!username().empty()) { + fbstring userInformation(username()); + + if (!password().empty()) { + userInformation += fbstring(":") + password(); + } + + result = userInformation + "@" + result; + } + + return result; +} + } // namespace folly diff --git a/folly/Uri.h b/folly/Uri.h index 5ed0a1b7..b036058d 100644 --- a/folly/Uri.h +++ b/folly/Uri.h @@ -53,6 +53,8 @@ class Uri { const fbstring& query() const { return query_; } const fbstring& fragment() const { return fragment_; } + fbstring authority() const; + template String toString() const;