From d64ddb54caacc3d07448d4bf4a90edd3d148cc4f Mon Sep 17 00:00:00 2001
From: Rider Linden <rider@lindenlab.com>
Date: Tue, 3 Nov 2015 14:22:42 -0800
Subject: [PATCH] MAINT-5820: Add a success/failure result to HTTP body parse
 method and react to that rather than an "undefined" LLSD

---
 indra/llmessage/llcorehttputil.cpp | 26 ++++++++++++++++----------
 indra/llmessage/llcorehttputil.h   |  2 +-
 2 files changed, 17 insertions(+), 11 deletions(-)

diff --git a/indra/llmessage/llcorehttputil.cpp b/indra/llmessage/llcorehttputil.cpp
index 9d3b8fcc1e3..9a23ede81ba 100644
--- a/indra/llmessage/llcorehttputil.cpp
+++ b/indra/llmessage/llcorehttputil.cpp
@@ -248,6 +248,7 @@ void HttpCoroHandler::onCompleted(LLCore::HttpHandle handle, LLCore::HttpRespons
 
     if (!status)
     {
+        bool parseSuccess(false);
         result = LLSD::emptyMap();
         LLCore::HttpStatus::type_enum_t errType = status.getType();
 
@@ -259,7 +260,7 @@ void HttpCoroHandler::onCompleted(LLCore::HttpHandle handle, LLCore::HttpRespons
             << LL_ENDL;
         if ((errType >= 400) && (errType < 500))
         {
-            LLSD body = this->parseBody(response);
+            LLSD body = this->parseBody(response, parseSuccess);
             if (!body.isUndefined())
             {
                 if (!body.isMap())
@@ -362,7 +363,7 @@ class HttpCoroLLSDHandler : public HttpCoroHandler
 
 protected:
     virtual LLSD handleSuccess(LLCore::HttpResponse * response, LLCore::HttpStatus &status);
-    virtual LLSD parseBody(LLCore::HttpResponse *response);
+    virtual LLSD parseBody(LLCore::HttpResponse *response, bool &success);
 };
 
 //-------------------------------------------------------------------------
@@ -377,9 +378,9 @@ LLSD HttpCoroLLSDHandler::handleSuccess(LLCore::HttpResponse * response, LLCore:
     LLSD result;
 
 //    const bool emit_parse_errors = false;
+    bool success(false);
 
-
-    result = parseBody(response);
+    result = parseBody(response, success);
 
 #if 0
     bool parsed = !((response->getBodySize() == 0) ||
@@ -403,7 +404,7 @@ LLSD HttpCoroLLSDHandler::handleSuccess(LLCore::HttpResponse * response, LLCore:
     }
 #endif
 
-    if (result.isUndefined())
+    if (!success)
     {   
 #if 1
         // Only emit a warning if we failed to parse when 'content-type' == 'application/llsd+xml'
@@ -437,8 +438,9 @@ LLSD HttpCoroLLSDHandler::handleSuccess(LLCore::HttpResponse * response, LLCore:
     return result;
 }
 
-LLSD HttpCoroLLSDHandler::parseBody(LLCore::HttpResponse *response)
+LLSD HttpCoroLLSDHandler::parseBody(LLCore::HttpResponse *response, bool &success)
 {
+    success = true;
     if (response->getBodySize() == 0)
         return LLSD();
 
@@ -446,6 +448,7 @@ LLSD HttpCoroLLSDHandler::parseBody(LLCore::HttpResponse *response)
 
     if (!LLCoreHttpUtil::responseToLLSD(response, true, result))
     {
+        success = false;
         return LLSD();
     }
 
@@ -467,7 +470,7 @@ class HttpCoroRawHandler : public HttpCoroHandler
     HttpCoroRawHandler(LLEventStream &reply);
 
     virtual LLSD handleSuccess(LLCore::HttpResponse * response, LLCore::HttpStatus &status);
-    virtual LLSD parseBody(LLCore::HttpResponse *response);
+    virtual LLSD parseBody(LLCore::HttpResponse *response, bool &success);
 };
 
 //-------------------------------------------------------------------------
@@ -522,8 +525,9 @@ LLSD HttpCoroRawHandler::handleSuccess(LLCore::HttpResponse * response, LLCore::
     return result;
 }
 
-LLSD HttpCoroRawHandler::parseBody(LLCore::HttpResponse *response)
+LLSD HttpCoroRawHandler::parseBody(LLCore::HttpResponse *response, bool &success)
 {
+    success = true;
     return LLSD();
 }
 
@@ -541,7 +545,7 @@ class HttpCoroJSONHandler : public HttpCoroHandler
     HttpCoroJSONHandler(LLEventStream &reply);
 
     virtual LLSD handleSuccess(LLCore::HttpResponse * response, LLCore::HttpStatus &status);
-    virtual LLSD parseBody(LLCore::HttpResponse *response);
+    virtual LLSD parseBody(LLCore::HttpResponse *response, bool &success);
 };
 
 //-------------------------------------------------------------------------
@@ -579,8 +583,9 @@ LLSD HttpCoroJSONHandler::handleSuccess(LLCore::HttpResponse * response, LLCore:
     return result;
 }
 
-LLSD HttpCoroJSONHandler::parseBody(LLCore::HttpResponse *response)
+LLSD HttpCoroJSONHandler::parseBody(LLCore::HttpResponse *response, bool &success)
 {
+    success = true;
     BufferArray * body(response->getBody());
     if (!body || !body->size())
     {
@@ -596,6 +601,7 @@ LLSD HttpCoroJSONHandler::parseBody(LLCore::HttpResponse *response)
     }
     catch (std::runtime_error e)
     {   
+        success = false;
         return LLSD();
     }
 
diff --git a/indra/llmessage/llcorehttputil.h b/indra/llmessage/llcorehttputil.h
index 0ec17cda078..d21f5ff45c3 100644
--- a/indra/llmessage/llcorehttputil.h
+++ b/indra/llmessage/llcorehttputil.h
@@ -282,7 +282,7 @@ class HttpCoroHandler : public LLCore::HttpHandler
 protected:
     /// this method may modify the status value
     virtual LLSD handleSuccess(LLCore::HttpResponse * response, LLCore::HttpStatus &status) = 0;
-    virtual LLSD parseBody(LLCore::HttpResponse *response) = 0;
+    virtual LLSD parseBody(LLCore::HttpResponse *response, bool &success) = 0;
 
 private:
     void buildStatusEntry(LLCore::HttpResponse *response, LLCore::HttpStatus status, LLSD &result);
-- 
GitLab