Versioning for Thrift, remove thrift/lib/cpp/config.h
[folly.git] / folly / Uri.cpp
index 9d4ad2acf37535f7ba5487bdeea051b45bf73ec2..5b2c155b80e7853888040a61476b191ac34fccde 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2013 Facebook, Inc.
+ * Copyright 2014 Facebook, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-#include "folly/Uri.h"
+#include <folly/Uri.h>
 
 #include <ctype.h>
 #include <boost/regex.hpp>
@@ -64,8 +64,8 @@ Uri::Uri(StringPiece str) : port_(0) {
   } else {
     static const boost::regex authorityRegex(
         "(?:([^@:]*)(?::([^@]*))?@)?"  // username, password
-        "(\\[[^\\]]*\\]|[^\\[:]*)"     // host (IP-literal, dotted-IPv4, or
-                                       // named host)
+        "(\\[[^\\]]*\\]|[^\\[:]*)"     // host (IP-literal (e.g. '['+IPv6+']',
+                                       // dotted-IPv4, or named host)
         "(?::(\\d*))?");               // port
 
     auto authority = authorityAndPathMatch[1];
@@ -121,4 +121,13 @@ fbstring Uri::authority() const {
   return result;
 }
 
+fbstring Uri::hostname() const {
+  if (host_.size() > 0 && host_[0] == '[') {
+    // If it starts with '[', then it should end with ']', this is ensured by
+    // regex
+    return host_.substr(1, host_.size() - 2);
+  }
+  return host_;
+}
+
 }  // namespace folly