You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by be...@apache.org on 2012/10/17 21:58:09 UTC

svn commit: r1399406 - /incubator/mesos/trunk/third_party/libprocess/src/encoder.hpp

Author: benh
Date: Wed Oct 17 19:58:09 2012
New Revision: 1399406

URL: http://svn.apache.org/viewvc?rev=1399406&view=rev
Log:
Fixed a regression in Response encoding lacking the Content-Length
header.

From: Ben Mahler <be...@gmail.com>
Review: https://reviews.apache.org/r/7609

Modified:
    incubator/mesos/trunk/third_party/libprocess/src/encoder.hpp

Modified: incubator/mesos/trunk/third_party/libprocess/src/encoder.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/third_party/libprocess/src/encoder.hpp?rev=1399406&r1=1399405&r2=1399406&view=diff
==============================================================================
--- incubator/mesos/trunk/third_party/libprocess/src/encoder.hpp (original)
+++ incubator/mesos/trunk/third_party/libprocess/src/encoder.hpp Wed Oct 17 19:58:09 2012
@@ -10,6 +10,7 @@
 
 #include <stout/foreach.hpp>
 #include <stout/hashmap.hpp>
+#include <stout/numify.hpp>
 
 
 namespace process {
@@ -146,10 +147,10 @@ public:
     // Add a Content-Length header if the response is of type "none"
     // or "body" and no Content-Length header has been supplied.
     if (response.type == http::Response::NONE &&
-        headers.contains("Content-Length")) {
+        !headers.contains("Content-Length")) {
       out << "Content-Length: 0\r\n";
     } else if (response.type == http::Response::BODY &&
-               headers.contains("Content-Length")) {
+               !headers.contains("Content-Length")) {
       out << "Content-Length: " << response.body.size() << "\r\n";
     }
 
@@ -158,7 +159,14 @@ public:
 
     // Add the body if necessary.
     if (response.type == http::Response::BODY) {
-      out.write(response.body.data(), response.body.size());
+      // If the Content-Length header was supplied, only write as much data
+      // as the length specifies.
+      Result<uint32_t> length = numify<uint32_t>(headers.get("Content-Length"));
+      if (length.isSome() && length.get() <= response.body.length()) {
+        out.write(response.body.data(), length.get());
+      } else {
+        out.write(response.body.data(), response.body.size());
+      }
     }
 
     return out.str();