You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by al...@apache.org on 2018/01/25 19:05:32 UTC
[1/2] mesos git commit: Added explicit scopes for clarity in
HTTPTest.Endpoints test.
Repository: mesos
Updated Branches:
refs/heads/master 657dc0506 -> abd1751aa
Added explicit scopes for clarity in HTTPTest.Endpoints test.
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/a94a8a67
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/a94a8a67
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/a94a8a67
Branch: refs/heads/master
Commit: a94a8a67900ceabdce5a83233e66938d6dd1917a
Parents: 657dc05
Author: Alexander Rukletsov <al...@apache.org>
Authored: Thu Jan 25 19:48:34 2018 +0100
Committer: Alexander Rukletsov <al...@apache.org>
Committed: Thu Jan 25 20:04:13 2018 +0100
----------------------------------------------------------------------
3rdparty/libprocess/src/tests/http_tests.cpp | 95 ++++++++++++-----------
1 file changed, 51 insertions(+), 44 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/a94a8a67/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 f79d366..e23f284 100644
--- a/3rdparty/libprocess/src/tests/http_tests.cpp
+++ b/3rdparty/libprocess/src/tests/http_tests.cpp
@@ -237,66 +237,73 @@ TEST_P(HTTPTest, Endpoints)
Http http;
// First hit '/body' (using explicit sockets and HTTP/1.0).
- Try<inet::Socket> create = inet::Socket::create();
- ASSERT_SOME(create);
-
- inet::Socket socket = create.get();
-
- AWAIT_READY(socket.connect(http.process->self().address));
+ {
+ Try<inet::Socket> create = inet::Socket::create();
+ ASSERT_SOME(create);
- std::ostringstream out;
- out << "GET /" << http.process->self().id << "/body"
- << " HTTP/1.0\r\n"
- << "Connection: Keep-Alive\r\n"
- << "\r\n";
+ inet::Socket socket = create.get();
- const string data = out.str();
+ AWAIT_READY(socket.connect(http.process->self().address));
- EXPECT_CALL(*http.process, body(_))
- .WillOnce(Return(http::OK()));
+ std::ostringstream out;
+ out << "GET /" << http.process->self().id << "/body"
+ << " HTTP/1.0\r\n"
+ << "Connection: Keep-Alive\r\n"
+ << "\r\n";
- AWAIT_READY(socket.send(data));
+ const string data = out.str();
+ const string response = "HTTP/1.1 200 OK";
- string response = "HTTP/1.1 200 OK";
+ EXPECT_CALL(*http.process, body(_))
+ .WillOnce(Return(http::OK()));
- AWAIT_EXPECT_EQ(response, socket.recv(response.size()));
+ AWAIT_READY(socket.send(data));
+ AWAIT_EXPECT_EQ(response, socket.recv(response.size()));
+ }
- // Now hit '/pipe' (by using http::get).
- http::Pipe pipe;
- http::OK ok;
- ok.type = http::Response::PIPE;
- ok.reader = pipe.reader();
+ // Test that an endpoint handler failure results in a 500.
+ {
+ EXPECT_CALL(*http.process, body(_))
+ .WillOnce(Return(Future<http::Response>::failed("failure")));
- Future<Nothing> request;
- EXPECT_CALL(*http.process, pipe(_))
- .WillOnce(DoAll(FutureSatisfy(&request),
- Return(ok)));
+ Future<http::Response> response =
+ http::get(http.process->self(), "body", None(), None(), GetParam());
- Future<http::Response> future =
- http::get(http.process->self(), "pipe", None(), None(), GetParam());
+ AWAIT_ASSERT_RESPONSE_STATUS_EQ(
+ http::InternalServerError().status,
+ response);
+ EXPECT_EQ("failure", response->body);
+ }
- AWAIT_READY(request);
+ // Now hit '/pipe' (by using http::get).
+ {
+ http::Pipe pipe;
+ http::OK ok;
+ ok.type = http::Response::PIPE;
+ ok.reader = pipe.reader();
- // Write the response.
- http::Pipe::Writer writer = pipe.writer();
- EXPECT_TRUE(writer.write("Hello World\n"));
- EXPECT_TRUE(writer.close());
+ Future<Nothing> request;
+ EXPECT_CALL(*http.process, pipe(_))
+ .WillOnce(DoAll(FutureSatisfy(&request),
+ Return(ok)));
- AWAIT_READY(future);
- EXPECT_EQ(http::Status::OK, future->code);
- EXPECT_EQ(http::Status::string(http::Status::OK), future->status);
+ Future<http::Response> future =
+ http::get(http.process->self(), "pipe", None(), None(), GetParam());
- EXPECT_SOME_EQ("chunked", future->headers.get("Transfer-Encoding"));
- EXPECT_EQ("Hello World\n", future->body);
+ AWAIT_READY(request);
- // Test that an endpoint handler failure results in a 500.
- EXPECT_CALL(*http.process, body(_))
- .WillOnce(Return(Future<http::Response>::failed("failure")));
+ // Write the response.
+ http::Pipe::Writer writer = pipe.writer();
+ EXPECT_TRUE(writer.write("Hello World\n"));
+ EXPECT_TRUE(writer.close());
- future = http::get(http.process->self(), "body", None(), None(), GetParam());
+ AWAIT_READY(future);
+ EXPECT_EQ(http::Status::OK, future->code);
+ EXPECT_EQ(http::Status::string(http::Status::OK), future->status);
- AWAIT_ASSERT_RESPONSE_STATUS_EQ(http::InternalServerError().status, future);
- EXPECT_EQ("failure", future->body);
+ EXPECT_SOME_EQ("chunked", future->headers.get("Transfer-Encoding"));
+ EXPECT_EQ("Hello World\n", future->body);
+ }
}
[2/2] mesos git commit: Updated libprocess routing to treat trailing
'/' as insignificant.
Posted by al...@apache.org.
Updated libprocess routing to treat trailing '/' as insignificant.
Prior to this patch, adding a trailing '/' to a valid URL path, e.g.,
"/state/", yielded a 404 response. This patch ensures that two URLs
which differ only in trailing '/' produce the same result.
This is achieved by (1) trimming a trailing '/' when processing a
request and (2) disallowing `route()` calls from using `/`.
Review: https://reviews.apache.org/r/64574
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/abd1751a
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/abd1751a
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/abd1751a
Branch: refs/heads/master
Commit: abd1751aa9a305b0648f4a630acbc84e7d837783
Parents: a94a8a6
Author: Alexander Rukletsov <al...@apache.org>
Authored: Wed Dec 13 14:35:42 2017 +0100
Committer: Alexander Rukletsov <al...@apache.org>
Committed: Thu Jan 25 20:05:07 2018 +0100
----------------------------------------------------------------------
3rdparty/libprocess/include/process/process.hpp | 2 +-
3rdparty/libprocess/src/process.cpp | 13 +++++++++++++
3rdparty/libprocess/src/tests/http_tests.cpp | 12 ++++++++++++
3 files changed, 26 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/abd1751a/3rdparty/libprocess/include/process/process.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/include/process/process.hpp b/3rdparty/libprocess/include/process/process.hpp
index 8b8323f..8661706 100644
--- a/3rdparty/libprocess/include/process/process.hpp
+++ b/3rdparty/libprocess/include/process/process.hpp
@@ -271,7 +271,7 @@ protected:
* Sets up a handler for HTTP requests with the specified name.
*
* @param name The endpoint or URL to route.
- * Must begin with a `/`.
+ * Must begin with a `/` and must not end with a '/'.
*/
void route(
const std::string& name,
http://git-wip-us.apache.org/repos/asf/mesos/blob/abd1751a/3rdparty/libprocess/src/process.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/process.cpp b/3rdparty/libprocess/src/process.cpp
index 52b4927..ba9bc29 100644
--- a/3rdparty/libprocess/src/process.cpp
+++ b/3rdparty/libprocess/src/process.cpp
@@ -3579,6 +3579,11 @@ void ProcessBase::consume(HttpEvent&& event)
event.request->url.path, "/" + tokens[0], strings::PREFIX);
name = strings::trim(name, strings::PREFIX, "/");
+ // Normalize the name by trimming the trailing '/'. We enforce that requests
+ // to ".../path/" are resolved with the ".../path" route. The trailing slash
+ // is stripped here in order to accomplish this.
+ name = strings::trim(name, strings::SUFFIX, "/");
+
// Look for an endpoint handler for this path. We begin with the full path,
// but if no handler is found and the path is nested, we shorten it and look
// again. For example: if the request is for '/a/b/c' and no handler is found,
@@ -3789,6 +3794,10 @@ void ProcessBase::route(
// Routes must start with '/'.
CHECK(name.find('/') == 0);
+ // To avoid ambiguity between "/path" and "/path/" we disallow the latter.
+ CHECK(name.size() == 1 || name.back() != '/')
+ << "Routes must not end with '/'" << ": " << name;
+
HttpEndpoint endpoint;
endpoint.handler = handler;
endpoint.options = options;
@@ -3809,6 +3818,10 @@ void ProcessBase::route(
// Routes must start with '/'.
CHECK(name.find('/') == 0);
+ // To avoid ambiguity between "/path" and "/path/" we disallow the latter.
+ CHECK(name.size() == 1 || name.back() != '/')
+ << "Routes must not end with '/'" << ": " << name;
+
HttpEndpoint endpoint;
endpoint.realm = realm;
endpoint.authenticatedHandler = handler;
http://git-wip-us.apache.org/repos/asf/mesos/blob/abd1751a/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 e23f284..a60f6b1 100644
--- a/3rdparty/libprocess/src/tests/http_tests.cpp
+++ b/3rdparty/libprocess/src/tests/http_tests.cpp
@@ -261,6 +261,18 @@ TEST_P(HTTPTest, Endpoints)
AWAIT_EXPECT_EQ(response, socket.recv(response.size()));
}
+ // Now hit '/body/' (by using http::get) and ensure it succeeds as well
+ // and resolved with the '/body' route.
+ {
+ EXPECT_CALL(*http.process, body(_))
+ .WillOnce(Return(http::OK()));
+
+ Future<http::Response> response =
+ http::get(http.process->self(), "body/", None(), None(), GetParam());
+
+ AWAIT_ASSERT_RESPONSE_STATUS_EQ(http::OK().status, response);
+ }
+
// Test that an endpoint handler failure results in a 500.
{
EXPECT_CALL(*http.process, body(_))