Repository: mesos
Updated Branches:
  refs/heads/master bfeb070a2 -> 82fb36ac0


Updated http::URL to a URI-reference.

Review: https://reviews.apache.org/r/38596


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/2fd5ed9e
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/2fd5ed9e
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/2fd5ed9e

Branch: refs/heads/master
Commit: 2fd5ed9ef150524d50a8e79c1a71c6292de68ac3
Parents: b06e932
Author: Benjamin Mahler <[email protected]>
Authored: Thu Sep 17 15:07:59 2015 -0700
Committer: Benjamin Mahler <[email protected]>
Committed: Mon Sep 28 10:38:01 2015 -0700

----------------------------------------------------------------------
 3rdparty/libprocess/include/process/http.hpp |  9 +++--
 3rdparty/libprocess/src/http.cpp             | 41 ++++++++++++++---------
 2 files changed, 32 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/2fd5ed9e/3rdparty/libprocess/include/process/http.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/include/process/http.hpp 
b/3rdparty/libprocess/include/process/http.hpp
index fbd6cf7..c71efcc 100644
--- a/3rdparty/libprocess/include/process/http.hpp
+++ b/3rdparty/libprocess/include/process/http.hpp
@@ -663,6 +663,10 @@ std::string encode(const hashmap<std::string, 
std::string>& query);
 
 // Represents a Uniform Resource Locator:
 //   scheme://domain|ip:port/path?query#fragment
+//
+// This is actually a URI-reference (see 4.1 of RFC 3986).
+//
+// TODO(bmahler): The default port should depend on the scheme!
 struct URL
 {
   URL(const std::string& _scheme,
@@ -693,11 +697,12 @@ struct URL
       query(_query),
       fragment(_fragment) {}
 
-  std::string scheme;
+  Option<std::string> scheme;
+
   // TODO(benh): Consider using unrestricted union for 'domain' and 'ip'.
   Option<std::string> domain;
   Option<net::IP> ip;
-  uint16_t port;
+  Option<uint16_t> port;
   std::string path;
   hashmap<std::string, std::string> query;
   Option<std::string> fragment;

http://git-wip-us.apache.org/repos/asf/mesos/blob/2fd5ed9e/3rdparty/libprocess/src/http.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/http.cpp b/3rdparty/libprocess/src/http.cpp
index 9ad613a..b4ab772 100644
--- a/3rdparty/libprocess/src/http.cpp
+++ b/3rdparty/libprocess/src/http.cpp
@@ -595,7 +595,9 @@ std::string encode(const hashmap<std::string, std::string>& 
query)
 
 ostream& operator<<(ostream& stream, const URL& url)
 {
-  stream << url.scheme << "://";
+  if (url.scheme.isSome()) {
+    stream << url.scheme.get() << "://";
+  }
 
   if (url.domain.isSome()) {
     stream << url.domain.get();
@@ -603,7 +605,9 @@ ostream& operator<<(ostream& stream, const URL& url)
     stream << url.ip.get();
   }
 
-  stream << ":" << url.port;
+  if (url.port.isSome()) {
+    stream << ":" << url.port.get();
+  }
 
   stream << "/" << strings::remove(url.path, "/", strings::PREFIX);
 
@@ -771,32 +775,33 @@ Future<Response> request(
     const Option<string>& body,
     const Option<string>& contentType)
 {
-  auto create = [&url]() -> Try<Socket> {
-    if (url.scheme == "http") {
+  Try<Socket> socket = [&url]() -> Try<Socket> {
+    // Default to 'http' if no scheme was specified.
+    if (url.scheme.isNone() || url.scheme == string("http")) {
       return Socket::create(Socket::POLL);
     }
 
+    if (url.scheme == string("https")) {
 #ifdef USE_SSL_SOCKET
-    if (url.scheme == "https") {
       return Socket::create(Socket::SSL);
-    }
+#else
+      return Error("'https' scheme requires SSL enabled");
 #endif
+    }
 
     return Error("Unsupported URL scheme");
   }();
 
-  if (create.isError()) {
-    return Failure("Failed to create socket: " + create.error());
+  if (socket.isError()) {
+    return Failure("Failed to create socket: " + socket.error());
   }
 
-  Socket socket = create.get();
-
   Address address;
 
   if (url.ip.isSome()) {
     address.ip = url.ip.get();
   } else if (url.domain.isNone()) {
-    return Failure("Missing URL domain or IP");
+    return Failure("Expecting url.ip or url.domain to be set");
   } else {
     Try<net::IP> ip = net::getIP(url.domain.get(), AF_INET);
 
@@ -808,11 +813,15 @@ Future<Response> request(
     address.ip = ip.get();
   }
 
-  address.port = url.port;
+  if (url.port.isNone()) {
+    return Failure("Expecting url.port to be set");
+  }
+
+  address.port = url.port.get();
 
-  return socket.connect(address)
+  return socket->connect(address)
     .then(lambda::bind(&_request,
-                       socket,
+                       socket.get(),
                        address,
                        url,
                        method,
@@ -864,11 +873,11 @@ Future<Response> _request(
   // Need to specify the 'Host' header.
   if (url.domain.isSome()) {
     // Use ONLY domain for standard ports.
-    if (url.port == 80 || url.port == 443) {
+    if (url.port.isNone() || url.port == 80 || url.port == 443) {
       headers["Host"] = url.domain.get();
     } else {
       // Add port for non-standard ports.
-      headers["Host"] = url.domain.get() + ":" + stringify(url.port);
+      headers["Host"] = url.domain.get() + ":" + stringify(url.port.get());
     }
   } else {
     headers["Host"] = stringify(address);

Reply via email to