You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by jo...@apache.org on 2015/12/10 17:54:06 UTC
[1/3] mesos git commit: Libprocess: Made `MethodNotAllowed` response
compliant to RFC 2616.
Repository: mesos
Updated Branches:
refs/heads/master 2ecd10240 -> e6114795d
Libprocess: Made `MethodNotAllowed` response compliant to RFC 2616.
According to RFC 2616 the `MethodNotAllowed` response must include an
'Allow' header containing a list of valid methods.
Review: https://reviews.apache.org/r/40905
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/bf82b570
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/bf82b570
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/bf82b570
Branch: refs/heads/master
Commit: bf82b57002618105da6f99a99f9ae7ee14a76208
Parents: 2ecd102
Author: Alexander Rukletsov <ru...@gmail.com>
Authored: Thu Dec 10 08:22:56 2015 -0800
Committer: Joris Van Remoortere <jo...@gmail.com>
Committed: Thu Dec 10 08:38:49 2015 -0800
----------------------------------------------------------------------
3rdparty/libprocess/include/process/http.hpp | 20 +++++++++++++++++---
1 file changed, 17 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/bf82b570/3rdparty/libprocess/include/process/http.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/include/process/http.hpp b/3rdparty/libprocess/include/process/http.hpp
index 3f33b46..c9e38e5 100644
--- a/3rdparty/libprocess/include/process/http.hpp
+++ b/3rdparty/libprocess/include/process/http.hpp
@@ -17,6 +17,7 @@
#include <stdint.h>
#include <atomic>
+#include <initializer_list>
#include <iosfwd>
#include <memory>
#include <queue>
@@ -575,10 +576,23 @@ struct NotFound : Response
struct MethodNotAllowed : Response
{
- MethodNotAllowed() : Response(Status::METHOD_NOT_ALLOWED) {}
+ // According to RFC 2616, "An Allow header field MUST be present in a
+ // 405 (Method Not Allowed) response".
- explicit MethodNotAllowed(const std::string& body)
- : Response(body, Status::METHOD_NOT_ALLOWED) {}
+ explicit MethodNotAllowed(
+ const std::initializer_list<std::string>& allowedMethods)
+ : Response(Status::METHOD_NOT_ALLOWED)
+ {
+ headers["Allow"] = strings::join(", ", allowedMethods);
+ }
+
+ MethodNotAllowed(
+ const std::initializer_list<std::string>& allowedMethods,
+ const std::string& body)
+ : Response(body, Status::METHOD_NOT_ALLOWED)
+ {
+ headers["Allow"] = strings::join(", ", allowedMethods);
+ }
};
[2/3] mesos git commit: Made `MethodNotAllowed` response compliant to
RFC 2616.
Posted by jo...@apache.org.
Made `MethodNotAllowed` response compliant to RFC 2616.
According to RFC 2616 the `MethodNotAllowed` response must include an
'Allow' header containing a list of valid methods.
This updates the `MethodNotAllowed` constructor invocations.
Review: https://reviews.apache.org/r/40913
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/44bd0a2c
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/44bd0a2c
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/44bd0a2c
Branch: refs/heads/master
Commit: 44bd0a2c41ef64826bb2d5a003bb9c3c8bf1bc4a
Parents: bf82b57
Author: Alexander Rukletsov <ru...@gmail.com>
Authored: Thu Dec 10 08:23:07 2015 -0800
Committer: Joris Van Remoortere <jo...@gmail.com>
Committed: Thu Dec 10 08:50:28 2015 -0800
----------------------------------------------------------------------
src/master/http.cpp | 2 +-
src/slave/http.cpp | 2 +-
src/tests/executor_http_api_tests.cpp | 2 +-
src/tests/scheduler_http_api_tests.cpp | 2 +-
4 files changed, 4 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/44bd0a2c/src/master/http.cpp
----------------------------------------------------------------------
diff --git a/src/master/http.cpp b/src/master/http.cpp
index 5d33138..dce248d 100644
--- a/src/master/http.cpp
+++ b/src/master/http.cpp
@@ -382,7 +382,7 @@ Future<Response> Master::Http::scheduler(const Request& request) const
if (request.method != "POST") {
return MethodNotAllowed(
- "Expecting a 'POST' request, received '" + request.method + "'");
+ {"POST"}, "Expecting 'POST', received '" + request.method + "'");
}
v1::scheduler::Call v1Call;
http://git-wip-us.apache.org/repos/asf/mesos/blob/44bd0a2c/src/slave/http.cpp
----------------------------------------------------------------------
diff --git a/src/slave/http.cpp b/src/slave/http.cpp
index cef568d..d1b1158 100644
--- a/src/slave/http.cpp
+++ b/src/slave/http.cpp
@@ -221,7 +221,7 @@ Future<Response> Slave::Http::executor(const Request& request) const
if (request.method != "POST") {
return MethodNotAllowed(
- "Expecting a 'POST' request, received '" + request.method + "'");
+ {"POST"}, "Expecting 'POST', received '" + request.method + "'");
}
v1::executor::Call v1Call;
http://git-wip-us.apache.org/repos/asf/mesos/blob/44bd0a2c/src/tests/executor_http_api_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/executor_http_api_tests.cpp b/src/tests/executor_http_api_tests.cpp
index 1be657c..8d86df5 100644
--- a/src/tests/executor_http_api_tests.cpp
+++ b/src/tests/executor_http_api_tests.cpp
@@ -312,7 +312,7 @@ TEST_F(ExecutorHttpApiTest, GetRequest)
"api/v1/executor");
AWAIT_READY(response);
- AWAIT_EXPECT_RESPONSE_STATUS_EQ(MethodNotAllowed().status, response);
+ AWAIT_EXPECT_RESPONSE_STATUS_EQ(MethodNotAllowed({"POST"}).status, response);
Shutdown();
}
http://git-wip-us.apache.org/repos/asf/mesos/blob/44bd0a2c/src/tests/scheduler_http_api_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/scheduler_http_api_tests.cpp b/src/tests/scheduler_http_api_tests.cpp
index 4f52309..4d23a5a 100644
--- a/src/tests/scheduler_http_api_tests.cpp
+++ b/src/tests/scheduler_http_api_tests.cpp
@@ -795,7 +795,7 @@ TEST_F(SchedulerHttpApiTest, GetRequest)
"api/v1/scheduler");
AWAIT_READY(response);
- AWAIT_EXPECT_RESPONSE_STATUS_EQ(MethodNotAllowed().status, response);
+ AWAIT_EXPECT_RESPONSE_STATUS_EQ(MethodNotAllowed({"POST"}).status, response);
}
} // namespace tests {
[3/3] mesos git commit: Replaced `BadRequest` with `MethodNotAllowed`
for unsupported methods.
Posted by jo...@apache.org.
Replaced `BadRequest` with `MethodNotAllowed` for unsupported methods.
Review: https://reviews.apache.org/r/40906
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/e6114795
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/e6114795
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/e6114795
Branch: refs/heads/master
Commit: e6114795de19d45cfce8c0a683bc48f02dcab320
Parents: 44bd0a2
Author: Alexander Rukletsov <ru...@gmail.com>
Authored: Thu Dec 10 08:23:22 2015 -0800
Committer: Joris Van Remoortere <jo...@gmail.com>
Committed: Thu Dec 10 08:51:11 2015 -0800
----------------------------------------------------------------------
src/master/http.cpp | 33 ++++++++++++++++++++++-----------
1 file changed, 22 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/e6114795/src/master/http.cpp
----------------------------------------------------------------------
diff --git a/src/master/http.cpp b/src/master/http.cpp
index dce248d..37fbcb9 100644
--- a/src/master/http.cpp
+++ b/src/master/http.cpp
@@ -551,7 +551,8 @@ static Resources removeDiskInfos(const Resources& resources)
Future<Response> Master::Http::createVolumes(const Request& request) const
{
if (request.method != "POST") {
- return BadRequest("Expecting POST");
+ return MethodNotAllowed(
+ {"POST"}, "Expecting 'POST', received '" + request.method + "'");
}
Result<Credential> credential = authenticate(request);
@@ -639,7 +640,8 @@ string Master::Http::DESTROY_VOLUMES_HELP()
Future<Response> Master::Http::destroyVolumes(const Request& request) const
{
if (request.method != "POST") {
- return BadRequest("Expecting POST");
+ return MethodNotAllowed(
+ {"POST"}, "Expecting 'POST', received '" + request.method + "'");
}
Result<Credential> credential = authenticate(request);
@@ -965,7 +967,8 @@ string Master::Http::RESERVE_HELP()
Future<Response> Master::Http::reserve(const Request& request) const
{
if (request.method != "POST") {
- return BadRequest("Expecting POST");
+ return MethodNotAllowed(
+ {"POST"}, "Expecting 'POST', received '" + request.method + "'");
}
Result<Credential> credential = authenticate(request);
@@ -1106,8 +1109,9 @@ Future<Response> Master::Http::quota(const Request& request) const
// TODO(joerg84): Add update logic for PUT requests
// once Quota supports updates.
- return BadRequest(
- "Expecting GET, DELETE or POST, got '" + request.method + "'");
+ return MethodNotAllowed(
+ {"GET", "POST", "DELETE"},
+ "Expecting 'GET', 'POST' or 'DELETE', received '" + request.method + "'");
}
@@ -1570,7 +1574,8 @@ string Master::Http::TEARDOWN_HELP()
Future<Response> Master::Http::teardown(const Request& request) const
{
if (request.method != "POST") {
- return BadRequest("Expecting POST");
+ return MethodNotAllowed(
+ {"POST"}, "Expecting 'POST', received '" + request.method + "'");
}
Result<Credential> credential = authenticate(request);
@@ -1787,7 +1792,9 @@ string Master::Http::MAINTENANCE_SCHEDULE_HELP()
Future<Response> Master::Http::maintenanceSchedule(const Request& request) const
{
if (request.method != "GET" && request.method != "POST") {
- return BadRequest("Expecting GET or POST, got '" + request.method + "'");
+ return MethodNotAllowed(
+ {"GET", "POST"},
+ "Expecting 'GET' or 'POST', received '" + request.method + "'");
}
// JSON-ify and return the current maintenance schedule.
@@ -1905,7 +1912,8 @@ string Master::Http::MACHINE_DOWN_HELP()
Future<Response> Master::Http::machineDown(const Request& request) const
{
if (request.method != "POST") {
- return BadRequest("Expecting POST, got '" + request.method + "'");
+ return MethodNotAllowed(
+ {"POST"}, "Expecting 'POST', received '" + request.method + "'");
}
// Parse the POST body as JSON.
@@ -2007,7 +2015,8 @@ string Master::Http::MACHINE_UP_HELP()
Future<Response> Master::Http::machineUp(const Request& request) const
{
if (request.method != "POST") {
- return BadRequest("Expecting POST, got '" + request.method + "'");
+ return MethodNotAllowed(
+ {"POST"}, "Expecting 'POST', received '" + request.method + "'");
}
// Parse the POST body as JSON.
@@ -2110,7 +2119,8 @@ string Master::Http::MAINTENANCE_STATUS_HELP()
Future<Response> Master::Http::maintenanceStatus(const Request& request) const
{
if (request.method != "GET") {
- return BadRequest("Expecting GET, got '" + request.method + "'");
+ return MethodNotAllowed(
+ {"GET"}, "Expecting 'GET', received '" + request.method + "'");
}
return master->allocator->getInverseOfferStatuses()
@@ -2182,7 +2192,8 @@ string Master::Http::UNRESERVE_HELP()
Future<Response> Master::Http::unreserve(const Request& request) const
{
if (request.method != "POST") {
- return BadRequest("Expecting POST");
+ return MethodNotAllowed(
+ {"POST"}, "Expecting 'POST', received '" + request.method + "'");
}
Result<Credential> credential = authenticate(request);