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 2015/08/14 13:03:40 UTC
mesos git commit: Added HTTP Delete Method.
Repository: mesos
Updated Branches:
refs/heads/master 0bdd72ad7 -> b39e59183
Added HTTP Delete Method.
Review: https://reviews.apache.org/r/36847
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/b39e5918
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/b39e5918
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/b39e5918
Branch: refs/heads/master
Commit: b39e591837b5c2afe0441783e2a082e11a30e2f9
Parents: 0bdd72a
Author: Joerg Schad <jo...@mesosphere.io>
Authored: Fri Aug 14 12:57:53 2015 +0200
Committer: Bernd Mathiske <be...@mesosphere.io>
Committed: Fri Aug 14 12:57:53 2015 +0200
----------------------------------------------------------------------
3rdparty/libprocess/include/process/http.hpp | 30 +++++++++++++++++++++++
3rdparty/libprocess/src/http.cpp | 26 ++++++++++++++++++++
3rdparty/libprocess/src/tests/http_tests.cpp | 28 +++++++++++++++++++++
3 files changed, 84 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/b39e5918/3rdparty/libprocess/include/process/http.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/include/process/http.hpp b/3rdparty/libprocess/include/process/http.hpp
index b829dad..fbd6cf7 100644
--- a/3rdparty/libprocess/include/process/http.hpp
+++ b/3rdparty/libprocess/include/process/http.hpp
@@ -710,6 +710,7 @@ std::ostream& operator<<(std::ostream& stream, const URL& url);
// TODO(bmahler): Consolidate these functions into a single
// http::request function that takes a 'Request' object.
+// TODO(joerg84): Make names consistent (see Mesos-3256).
// Asynchronously sends an HTTP GET request to the specified URL
// and returns the HTTP response of type 'BODY' once the entire
@@ -750,6 +751,35 @@ Future<Response> post(
const Option<std::string>& contentType = None());
+/**
+ * Asynchronously sends an HTTP DELETE request to the process with the
+ * given UPID and returns the HTTP response.
+ *
+ * @param url The target url for the request.
+ * @param headers Optional header for the request.
+ * @return A future with the HTTP response.
+ */
+Future<Response> requestDelete(
+ const URL& url,
+ const Option<hashmap<std::string, std::string>>& headers = None());
+
+
+/**
+ * Asynchronously sends an HTTP DELETE request to the process with the
+ * given UPID and returns the HTTP response.
+ *
+ * @param upid The target process's assigned untyped PID.
+ * @param path The optional path to be be deleted. If not send the
+ request is send to the process directly.
+ * @param headers Optional headers for the request.
+ * @return A future with the HTTP response.
+ */
+Future<Response> requestDelete(
+ const UPID& upid,
+ const Option<std::string>& path = None(),
+ const Option<hashmap<std::string, std::string>>& headers = None());
+
+
namespace streaming {
// Asynchronously sends an HTTP GET request to the specified URL
http://git-wip-us.apache.org/repos/asf/mesos/blob/b39e5918/3rdparty/libprocess/src/http.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/http.cpp b/3rdparty/libprocess/src/http.cpp
index b70e2fa..660950f 100644
--- a/3rdparty/libprocess/src/http.cpp
+++ b/3rdparty/libprocess/src/http.cpp
@@ -984,6 +984,32 @@ Future<Response> post(
}
+Future<Response> requestDelete(
+ const URL& url,
+ const Option<hashmap<string, string>>& headers)
+{
+ return internal::request(url, "DELETE", false, headers, None(), None());
+}
+
+
+Future<Response> requestDelete(
+ const UPID& upid,
+ const Option<string>& path,
+ const Option<hashmap<string, string>>& headers)
+{
+ URL url("http", net::IP(upid.address.ip), upid.address.port, upid.id);
+
+ if (path.isSome()) {
+ // TODO(joerg84): Handle 'query' and/or 'fragment' in 'path'.
+ // This could mean that we either remove these or even fail
+ // (see MESOS-3163).
+ url.path = strings::join("/", url.path, path.get());
+ }
+
+ return requestDelete(url, headers);
+}
+
+
namespace streaming {
Future<Response> get(
http://git-wip-us.apache.org/repos/asf/mesos/blob/b39e5918/3rdparty/libprocess/src/tests/http_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/tests/http_tests.cpp b/3rdparty/libprocess/src/tests/http_tests.cpp
index 7351fa4..92f914f 100644
--- a/3rdparty/libprocess/src/tests/http_tests.cpp
+++ b/3rdparty/libprocess/src/tests/http_tests.cpp
@@ -65,6 +65,7 @@ public:
MOCK_METHOD1(pipe, Future<http::Response>(const http::Request&));
MOCK_METHOD1(get, Future<http::Response>(const http::Request&));
MOCK_METHOD1(post, Future<http::Response>(const http::Request&));
+ MOCK_METHOD1(requestDelete, Future<http::Response>(const http::Request&));
void addRoute(const string& path, const HttpRequestHandler& handler)
{
@@ -79,6 +80,7 @@ protected:
route("/pipe", None(), &HttpProcess::pipe);
route("/get", None(), &HttpProcess::get);
route("/post", None(), &HttpProcess::post);
+ route("/delete", None(), &HttpProcess::requestDelete);
}
Future<http::Response> auth(const http::Request& request)
@@ -621,6 +623,32 @@ TEST(HTTPTest, Post)
}
+http::Response validateDelete(const http::Request& request)
+{
+ EXPECT_EQ("DELETE", request.method);
+ EXPECT_THAT(request.path, EndsWith("delete"));
+ EXPECT_TRUE(request.body.empty());
+ EXPECT_TRUE(request.query.empty());
+
+ return http::OK();
+}
+
+
+TEST(HTTPTest, Delete)
+{
+ Http http;
+
+ EXPECT_CALL(*http.process, requestDelete(_))
+ .WillOnce(Invoke(validateDelete));
+
+ Future<http::Response> future =
+ http::requestDelete(http.process->self(), "delete", None());
+
+ AWAIT_READY(future);
+ ASSERT_EQ(http::statuses[200], future.get().status);
+}
+
+
TEST(HTTPTest, QueryEncodeDecode)
{
// If we use Type<a, b> directly inside a macro without surrounding