You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by be...@apache.org on 2014/01/25 01:14:45 UTC
[4/7] git commit: Refined http get/post interfaces to use Option.
Refined http get/post interfaces to use Option.
From: Jie Yu <yu...@gmail.com>
Review: https://reviews.apache.org/r/17076
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/170b854b
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/170b854b
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/170b854b
Branch: refs/heads/master
Commit: 170b854b424c5a9d0272f98f128842f9a9d5afa8
Parents: 45a7739
Author: Benjamin Hindman <be...@gmail.com>
Authored: Sat Jan 18 10:23:17 2014 -0800
Committer: Benjamin Hindman <be...@gmail.com>
Committed: Fri Jan 24 16:14:01 2014 -0800
----------------------------------------------------------------------
3rdparty/libprocess/include/process/http.hpp | 17 +++-------
3rdparty/libprocess/src/process.cpp | 40 ++++++++++++++---------
2 files changed, 29 insertions(+), 28 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/170b854b/3rdparty/libprocess/include/process/http.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/include/process/http.hpp b/3rdparty/libprocess/include/process/http.hpp
index a8b1636..414a2b2 100644
--- a/3rdparty/libprocess/include/process/http.hpp
+++ b/3rdparty/libprocess/include/process/http.hpp
@@ -481,26 +481,17 @@ inline Try<std::string> decode(const std::string& s)
// on the read stream, rather than parsing the full string response at the end.
Future<Response> get(
const UPID& upid,
- const std::string& path = "",
+ const Option<std::string>& path = None(),
const Option<std::string>& query = None());
-// Backwards compatible wrapper for the above.
-// There are clients who pass in string literals to query that cannot be
-// converted automatically to Option<string>.
-Future<Response> get(
- const UPID& upid,
- const std::string& path,
- const std::string& query);
-
-
// Sends a blocking HTTP POST request to the process with the given upid.
// Returns the HTTP response from the process, read asyncronously.
Future<Response> post(
const UPID& upid,
- const std::string& path,
- const std::string& contentType,
- const std::string& body);
+ const Option<std::string>& path = None(),
+ const Option<std::string>& body = None(),
+ const Option<std::string>& contentType = None());
// Status code reason strings, from the HTTP1.1 RFC:
http://git-wip-us.apache.org/repos/asf/mesos/blob/170b854b/3rdparty/libprocess/src/process.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/process.cpp b/3rdparty/libprocess/src/process.cpp
index bc7a1c5..6ebeb62 100644
--- a/3rdparty/libprocess/src/process.cpp
+++ b/3rdparty/libprocess/src/process.cpp
@@ -3622,10 +3622,10 @@ Future<Response> decode(const string& buffer)
Future<Response> request(
const UPID& upid,
const string& method,
- const string& path,
+ const Option<string>& path,
const Option<string>& query,
- const Option<string>& contentType,
- const Option<string>& body)
+ const Option<string>& body,
+ const Option<string>& contentType)
{
int s = socket(AF_INET, SOCK_STREAM, IPPROTO_IP);
@@ -3651,10 +3651,16 @@ Future<Response> request(
std::ostringstream out;
- out << method << " /" << upid.id << "/" << path;
+ out << method << " /" << upid.id;
+
+ if (path.isSome()) {
+ out << "/" << path.get();
+ }
+
if (query.isSome()) {
out << "?" << query.get();
}
+
out << " HTTP/1.1\r\n";
// Call inet_ntop since inet_ntoa is not thread-safe!
@@ -3664,6 +3670,11 @@ Future<Response> request(
out << "Host: " << ip << ":" << upid.port << "\r\n"
<< "Connection: close\r\n";
+ if (body.isNone() && contentType.isSome()) {
+ os::close(s);
+ return Failure("Attempted to do a POST with a Content-Type but no body");
+ }
+
if (contentType.isSome()) {
out << "Content-Type: " << contentType.get() << "\r\n";
}
@@ -3709,23 +3720,22 @@ Future<Response> request(
} // namespace internal {
-Future<Response> get(const UPID& upid, const string& path, const Option<string>& query)
+Future<Response> get(
+ const UPID& upid,
+ const Option<string>& path,
+ const Option<string>& query)
{
return internal::request(upid, "GET", path, query, None(), None());
}
-// Overload for back-compat.
-Future<Response> get(const UPID& upid, const string& path, const string& query)
-{
- //In this overload empty string means no query.
- return get(upid, path, query.empty() ? Option<string>::none() : Some(query));
-}
-
-
-Future<Response> post(const UPID& upid, const string& path, const string& contentType, const string& body)
+Future<Response> post(
+ const UPID& upid,
+ const Option<string>& path,
+ const Option<string>& body,
+ const Option<string>& contentType)
{
- return internal::request(upid, "POST", path, None(), contentType, body);
+ return internal::request(upid, "POST", path, None(), body, contentType);
}
} // namespace http {