You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by an...@apache.org on 2016/12/08 00:57:15 UTC
[2/2] mesos git commit: Made the default 'Accept-Type' be JSON on the
Agent API.
Made the default 'Accept-Type' be JSON on the Agent API.
There might be existing clients that might not be setting the
'Accept-Type' header. If so, they would break if we change the
default accept type to being `APPLICATION_STREAMING_JSON`.
Review: https://reviews.apache.org/r/54502/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/bc3b7ab3
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/bc3b7ab3
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/bc3b7ab3
Branch: refs/heads/master
Commit: bc3b7ab3ec06dcca32b9d3090a11937622f59772
Parents: f216845
Author: Anand Mazumdar <an...@apache.org>
Authored: Wed Dec 7 16:54:37 2016 -0800
Committer: Anand Mazumdar <an...@apache.org>
Committed: Wed Dec 7 16:54:37 2016 -0800
----------------------------------------------------------------------
src/slave/http.cpp | 10 +++++-----
src/tests/api_tests.cpp | 36 ++++++++++++++++++++++++++++++++++++
2 files changed, 41 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/bc3b7ab3/src/slave/http.cpp
----------------------------------------------------------------------
diff --git a/src/slave/http.cpp b/src/slave/http.cpp
index 0c0e769..580a90b 100644
--- a/src/slave/http.cpp
+++ b/src/slave/http.cpp
@@ -366,14 +366,14 @@ Future<Response> Slave::Http::api(
};
ContentType acceptType;
- if (request.acceptsMediaType(APPLICATION_STREAMING_PROTOBUF)) {
- acceptType = ContentType::STREAMING_PROTOBUF;
- } else if (request.acceptsMediaType(APPLICATION_STREAMING_JSON)) {
- acceptType = ContentType::STREAMING_JSON;
- } else if (request.acceptsMediaType(APPLICATION_JSON)) {
+ if (request.acceptsMediaType(APPLICATION_JSON)) {
acceptType = ContentType::JSON;
} else if (request.acceptsMediaType(APPLICATION_PROTOBUF)) {
acceptType = ContentType::PROTOBUF;
+ } else if (request.acceptsMediaType(APPLICATION_STREAMING_JSON)) {
+ acceptType = ContentType::STREAMING_JSON;
+ } else if (request.acceptsMediaType(APPLICATION_STREAMING_PROTOBUF)) {
+ acceptType = ContentType::STREAMING_PROTOBUF;
} else {
return NotAcceptable(
string("Expecting 'Accept' to allow ") +
http://git-wip-us.apache.org/repos/asf/mesos/blob/bc3b7ab3/src/tests/api_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/api_tests.cpp b/src/tests/api_tests.cpp
index 0ec4b87..21aefb2 100644
--- a/src/tests/api_tests.cpp
+++ b/src/tests/api_tests.cpp
@@ -3935,6 +3935,42 @@ TEST_F(AgentAPITest, AttachContainerInputValidation)
}
+// This test verifies that the default 'Accept-Type' for the
+// Agent API endpoint is `APPLICATION_JSON`.
+TEST_P(AgentAPITest, DefaultAccept)
+{
+ Future<Nothing> __recover = FUTURE_DISPATCH(_, &Slave::__recover);
+
+ StandaloneMasterDetector detector;
+ Try<Owned<cluster::Slave>> slave = StartSlave(&detector);
+ ASSERT_SOME(slave);
+
+ AWAIT_READY(__recover);
+
+ // Wait until the agent has finished recovery.
+ Clock::pause();
+ Clock::settle();
+
+ process::http::Headers headers = createBasicAuthHeaders(DEFAULT_CREDENTIAL);
+ headers["Accept"] = "*/*";
+
+ v1::agent::Call call;
+ call.set_type(v1::agent::Call::GET_STATE);
+
+ ContentType contentType = GetParam();
+
+ Future<http::Response> response = http::post(
+ slave.get()->pid,
+ "api/v1",
+ headers,
+ serialize(contentType, call),
+ stringify(contentType));
+
+ AWAIT_EXPECT_RESPONSE_STATUS_EQ(http::OK().status, response);
+ AWAIT_EXPECT_RESPONSE_HEADER_EQ(APPLICATION_JSON, "Content-Type", response);
+}
+
+
class AgentAPIStreamingTest
: public MesosTest,
public WithParamInterface<ContentType> {};