From 464cc74d12be1772fb4846bf9a3c19b37024f6a7 Mon Sep 17 00:00:00 2001 From: Stephane Sezer Date: Mon, 23 Sep 2013 14:42:11 -0700 Subject: [PATCH] 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 --- folly/Uri.cpp | 22 ++++++++++++++++++++++ folly/Uri.h | 2 ++ 2 files changed, 24 insertions(+) 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; -- 2.34.1