]> granicus.if.org Git - icinga2/commitdiff
Revert "Fix incorrect socket handling for the HTTP client"
authorMichael Friedrich <michael.friedrich@icinga.com>
Tue, 16 Jan 2018 09:43:16 +0000 (10:43 +0100)
committerMichael Friedrich <michael.friedrich@icinga.com>
Tue, 16 Jan 2018 09:44:31 +0000 (10:44 +0100)
This reverts commit 59da943548c7c1be5f4b27dce73a0ad27cf0de5d.

refs #5760

lib/base/stream.cpp
lib/remote/httpresponse.cpp

index 57791d30522b0e2ab39012bcfb25ea361bb2f8a9..9390d97b9da0fdef82fff36d985bb9519ed176d1 100644 (file)
@@ -145,9 +145,6 @@ bool StreamReadContext::FillFromStream(const Stream::Ptr& stream, bool may_wait)
                if (!Buffer)
                        throw std::bad_alloc();
 
-               if (stream->IsEof())
-                       break;
-
                size_t rc = stream->Read(Buffer + Size, 4096, true);
 
                Size += rc;
index ab7458655a2f9422461e1bba9b3d0389392a9a25..7f77ed3865ee65286516a04bc27a1f11d5659e5f 100644 (file)
@@ -159,7 +159,12 @@ bool HttpResponse::Parse(StreamReadContext& src, bool may_wait)
 
                        if (line == "") {
                                m_State = HttpResponseBody;
-                               m_Body = new FIFO();
+
+                               /* we're done if the request doesn't contain a message body */
+                               if (!Headers->Contains("content-length") && !Headers->Contains("transfer-encoding"))
+                                       Complete = true;
+                               else
+                                       m_Body = new FIFO();
 
                                return true;
 
@@ -199,41 +204,27 @@ bool HttpResponse::Parse(StreamReadContext& src, bool may_wait)
                                return true;
                        }
                } else {
-                       bool hasLengthIndicator = false;
-                       size_t lengthIndicator = 0;
-                       Value contentLengthHeader;
-
-                       if (Headers->Get("content-length", &contentLengthHeader)) {
-                               hasLengthIndicator = true;
-                               lengthIndicator = Convert::ToLong(contentLengthHeader);
-                       }
-
-                       if (hasLengthIndicator && src.Eof)
+                       if (src.Eof)
                                BOOST_THROW_EXCEPTION(std::invalid_argument("Unexpected EOF in HTTP body"));
 
                        if (src.MustRead) {
-                               if (!src.FillFromStream(m_Stream, may_wait))
+                               if (!src.FillFromStream(m_Stream, false)) {
                                        src.Eof = true;
+                                       BOOST_THROW_EXCEPTION(std::invalid_argument("Unexpected EOF in HTTP body"));
+                               }
 
                                src.MustRead = false;
                        }
 
-                       if (!hasLengthIndicator)
-                               lengthIndicator = src.Size;
+                       size_t length_indicator = Convert::ToLong(Headers->Get("content-length"));
 
-                       if (src.Size < lengthIndicator) {
+                       if (src.Size < length_indicator) {
                                src.MustRead = true;
-                               return may_wait;
-                       }
-
-                       m_Body->Write(src.Buffer, lengthIndicator);
-                       src.DropData(lengthIndicator);
-
-                       if (!hasLengthIndicator && !src.Eof) {
-                               src.MustRead = true;
-                               return may_wait;
+                               return false;
                        }
 
+                       m_Body->Write(src.Buffer, length_indicator);
+                       src.DropData(length_indicator);
                        Complete = true;
                        return true;
                }