You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by bm...@apache.org on 2015/05/08 05:23:44 UTC

[2/3] mesos git commit: Added the client address to http::Request.

Added the client address to http::Request.

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


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

Branch: refs/heads/master
Commit: 21ee7fa5fba8c5e7e47b4dd34e15056720b1ee3b
Parents: 389995d
Author: Benjamin Mahler <be...@gmail.com>
Authored: Wed May 6 22:13:05 2015 -0700
Committer: Benjamin Mahler <be...@gmail.com>
Committed: Thu May 7 20:04:01 2015 -0700

----------------------------------------------------------------------
 3rdparty/libprocess/include/process/http.hpp | 5 +++++
 3rdparty/libprocess/src/process.cpp          | 8 +++++++-
 3rdparty/libprocess/src/tests/http_tests.cpp | 3 +++
 3 files changed, 15 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/21ee7fa5/3rdparty/libprocess/include/process/http.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/include/process/http.hpp b/3rdparty/libprocess/include/process/http.hpp
index 5210ce0..058fa02 100644
--- a/3rdparty/libprocess/include/process/http.hpp
+++ b/3rdparty/libprocess/include/process/http.hpp
@@ -10,6 +10,7 @@
 #include <string>
 #include <vector>
 
+#include <process/address.hpp>
 #include <process/future.hpp>
 #include <process/owned.hpp>
 #include <process/pid.hpp>
@@ -45,6 +46,10 @@ void initialize();
 
 struct Request
 {
+  // Contains the client's address. Note that this may
+  // correspond to a proxy or load balancer address.
+  network::Address client;
+
   // TODO(benh): Add major/minor version.
   // TODO(bmahler): Header names are not case sensitive! Either make these
   // case-insensitive, or add a variable for each header in HTTP 1.0/1.1 (like

http://git-wip-us.apache.org/repos/asf/mesos/blob/21ee7fa5/3rdparty/libprocess/src/process.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/process.cpp b/3rdparty/libprocess/src/process.cpp
index 8ab0dbc..588bd3e 100644
--- a/3rdparty/libprocess/src/process.cpp
+++ b/3rdparty/libprocess/src/process.cpp
@@ -567,11 +567,17 @@ void decode_recv(
     delete socket;
     return;
   }
+
   // Decode as much of the data as possible into HTTP requests.
-  const deque<Request*>& requests = decoder->decode(data, length.get());
+  deque<Request*> requests = decoder->decode(data, length.get());
 
   if (!requests.empty()) {
     foreach (Request* request, requests) {
+      // Augment each Request with the client's address. This should
+      // never fail since there remains a reference to this Socket!
+      Try<Address> address = socket->address();
+      CHECK_SOME(address);
+      request->client = address.get();
       process_manager->handle(decoder->socket(), request);
     }
   } else if (requests.empty() && decoder->failed()) {

http://git-wip-us.apache.org/repos/asf/mesos/blob/21ee7fa5/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 dfdb233..d29cd29 100644
--- a/3rdparty/libprocess/src/tests/http_tests.cpp
+++ b/3rdparty/libprocess/src/tests/http_tests.cpp
@@ -7,6 +7,7 @@
 
 #include <string>
 
+#include <process/address.hpp>
 #include <process/future.hpp>
 #include <process/gmock.hpp>
 #include <process/gtest.hpp>
@@ -368,6 +369,7 @@ TEST(HTTP, PathParse)
 
 http::Response validateGetWithoutQuery(const http::Request& request)
 {
+  EXPECT_NE(network::Address(), request.client);
   EXPECT_EQ("GET", request.method);
   EXPECT_THAT(request.path, EndsWith("get"));
   EXPECT_EQ("", request.body);
@@ -380,6 +382,7 @@ http::Response validateGetWithoutQuery(const http::Request& request)
 
 http::Response validateGetWithQuery(const http::Request& request)
 {
+  EXPECT_NE(network::Address(), request.client);
   EXPECT_EQ("GET", request.method);
   EXPECT_THAT(request.path, EndsWith("get"));
   EXPECT_EQ("", request.body);