You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by ji...@apache.org on 2017/01/18 14:59:22 UTC
mesos git commit: Added support for HTTP responses with unspecified
length.
Repository: mesos
Updated Branches:
refs/heads/master 24cbc0baa -> 3d21d776d
Added support for HTTP responses with unspecified length.
Some HTTP responses might not set the 'Content-Length' header. This
usually means that the message body should be read until EOF. This will
be done by an additional call of 'decoder.decode' with an empty string.
Review: https://reviews.apache.org/r/55496/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/3d21d776
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/3d21d776
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/3d21d776
Branch: refs/heads/master
Commit: 3d21d776d444acd288f3107b8edff326c6cc44ae
Parents: 24cbc0b
Author: Jan Schlicht <ja...@mesosphere.io>
Authored: Wed Jan 18 15:56:30 2017 +0100
Committer: Jie Yu <yu...@gmail.com>
Committed: Wed Jan 18 15:56:30 2017 +0100
----------------------------------------------------------------------
3rdparty/libprocess/src/http.cpp | 19 ++++++-------
3rdparty/libprocess/src/tests/decoder_tests.cpp | 29 ++++++++++++++++++++
2 files changed, 38 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/3d21d776/3rdparty/libprocess/src/http.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/http.cpp b/3rdparty/libprocess/src/http.cpp
index e2e9b8f..f4ae30b 100644
--- a/3rdparty/libprocess/src/http.cpp
+++ b/3rdparty/libprocess/src/http.cpp
@@ -763,27 +763,26 @@ Try<vector<Response>> decodeResponses(const string& s)
{
ResponseDecoder decoder;
- deque<http::Response*> responses = decoder.decode(s.data(), s.length());
+ vector<Response> result;
- if (decoder.failed()) {
+ auto appendResult = [&result](const deque<http::Response*>& responses) {
foreach (Response* response, responses) {
+ result.push_back(*response);
delete response;
}
+ };
+ appendResult(decoder.decode(s.data(), s.length()));
+ appendResult(decoder.decode("", 0));
+
+ if (decoder.failed()) {
return Error("Decoding failed");
}
- if (responses.empty()) {
+ if (result.empty()) {
return Error("No response decoded");
}
- vector<Response> result;
-
- foreach (Response* response, responses) {
- result.push_back(*response);
- delete response;
- }
-
return result;
}
http://git-wip-us.apache.org/repos/asf/mesos/blob/3d21d776/3rdparty/libprocess/src/tests/decoder_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/tests/decoder_tests.cpp b/3rdparty/libprocess/src/tests/decoder_tests.cpp
index 87563f4..c0efef5 100644
--- a/3rdparty/libprocess/src/tests/decoder_tests.cpp
+++ b/3rdparty/libprocess/src/tests/decoder_tests.cpp
@@ -160,6 +160,35 @@ TEST(DecoderTest, Response)
}
+TEST(DecoderTest, ResponseWithUnspecifiedLength)
+{
+ ResponseDecoder decoder;
+
+ const string data =
+ "HTTP/1.1 200 OK\r\n"
+ "Date: Fri, 31 Dec 1999 23:59:59 GMT\r\n"
+ "Content-Type: text/plain\r\n"
+ "\r\n"
+ "hi";
+
+ deque<http::Response*> responses = decoder.decode(data.data(), data.length());
+ ASSERT_FALSE(decoder.failed());
+ ASSERT_EQ(0u, responses.size());
+
+ responses = decoder.decode("", 0);
+ ASSERT_FALSE(decoder.failed());
+ ASSERT_EQ(1u, responses.size());
+
+ Owned<http::Response> response(responses[0]);
+
+ EXPECT_EQ("200 OK", response->status);
+ EXPECT_EQ(http::Response::BODY, response->type);
+ EXPECT_EQ("hi", response->body);
+
+ EXPECT_EQ(2u, response->headers.size());
+}
+
+
TEST(DecoderTest, StreamingResponse)
{
StreamingResponseDecoder decoder;