You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by mp...@apache.org on 2016/01/15 18:59:52 UTC

[2/4] mesos git commit: Added support for `jsonify` result to `OK` response in libprocess.

Added support for `jsonify` result to `OK` response in libprocess.

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


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

Branch: refs/heads/master
Commit: fb59990227f5218bf1070c49145f2c0797ee5ac4
Parents: 42cf29e
Author: Michael Park <mp...@apache.org>
Authored: Tue Dec 8 09:25:39 2015 -0500
Committer: Michael Park <mp...@apache.org>
Committed: Fri Jan 15 09:37:41 2016 -0800

----------------------------------------------------------------------
 3rdparty/libprocess/3rdparty/Makefile.am     |  1 +
 3rdparty/libprocess/include/process/http.hpp |  3 +++
 3rdparty/libprocess/src/http.cpp             | 25 +++++++++++++++++++++++
 3 files changed, 29 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/fb599902/3rdparty/libprocess/3rdparty/Makefile.am
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/Makefile.am b/3rdparty/libprocess/3rdparty/Makefile.am
index 084475a..596905a 100644
--- a/3rdparty/libprocess/3rdparty/Makefile.am
+++ b/3rdparty/libprocess/3rdparty/Makefile.am
@@ -172,6 +172,7 @@ stout_tests_SOURCES =				\
   $(STOUT)/tests/interval_tests.cpp		\
   $(STOUT)/tests/ip_tests.cpp                   \
   $(STOUT)/tests/json_tests.cpp			\
+  $(STOUT)/tests/jsonify_tests.cpp			\
   $(STOUT)/tests/linkedhashmap_tests.cpp	\
   $(STOUT)/tests/mac_tests.cpp                  \
   $(STOUT)/tests/main.cpp			\

http://git-wip-us.apache.org/repos/asf/mesos/blob/fb599902/3rdparty/libprocess/include/process/http.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/include/process/http.hpp b/3rdparty/libprocess/include/process/http.hpp
index d0f820e..1fe549e 100644
--- a/3rdparty/libprocess/include/process/http.hpp
+++ b/3rdparty/libprocess/include/process/http.hpp
@@ -35,6 +35,7 @@
 #include <stout/hashmap.hpp>
 #include <stout/ip.hpp>
 #include <stout/json.hpp>
+#include <stout/jsonify.hpp>
 #include <stout/none.hpp>
 #include <stout/nothing.hpp>
 #include <stout/option.hpp>
@@ -491,6 +492,8 @@ struct OK : Response
   explicit OK(const std::string& body) : Response(body, Status::OK) {}
 
   OK(const JSON::Value& value, const Option<std::string>& jsonp = None());
+
+  OK(JSON::Proxy&& value, const Option<std::string>& jsonp = None());
 };
 
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/fb599902/3rdparty/libprocess/src/http.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/http.cpp b/3rdparty/libprocess/src/http.cpp
index aabfd5d..40fd87c 100644
--- a/3rdparty/libprocess/src/http.cpp
+++ b/3rdparty/libprocess/src/http.cpp
@@ -566,6 +566,31 @@ OK::OK(const JSON::Value& value, const Option<string>& jsonp)
   body = out.str().data();
 }
 
+
+OK::OK(JSON::Proxy&& value, const Option<std::string>& jsonp)
+  : Response(Status::OK)
+{
+  type = BODY;
+
+  std::ostringstream out;
+
+  if (jsonp.isSome()) {
+    out << jsonp.get() << "(";
+  }
+
+  out << std::move(value);
+
+  if (jsonp.isSome()) {
+    out << ");";
+    headers["Content-Type"] = "text/javascript";
+  } else {
+    headers["Content-Type"] = "application/json";
+  }
+
+  body = out.str();
+  headers["Content-Length"] = stringify(body.size());
+}
+
 namespace path {
 
 Try<hashmap<string, string>> parse(const string& pattern, const string& path)