lordgamez commented on a change in pull request #1233:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1233#discussion_r783793699



##########
File path: extensions/http-curl/protocols/RESTSender.cpp
##########
@@ -102,17 +104,36 @@ const C2Payload RESTSender::sendPayload(const std::string 
url, const Direction d
   client.setKeepAliveIdle(std::chrono::milliseconds(2000));
   client.setConnectionTimeout(std::chrono::milliseconds(2000));
   if (direction == Direction::TRANSMIT) {
-    input = std::unique_ptr<utils::ByteInputCallBack>(new 
utils::ByteInputCallBack());
-    callback = std::unique_ptr<utils::HTTPUploadCallback>(new 
utils::HTTPUploadCallback());
-    input->write(outputConfig);
-    callback->ptr = input.get();
-    callback->pos = 0;
     client.set_request_method("POST");
     if (!ssl_context_service_ && url.find("https://";) == 0) {
       setSecurityContext(client, "POST", url);
     }
-    client.setUploadCallback(callback.get());
-    client.setPostSize(outputConfig.size());
+    if (payload.getOperation() == Operation::TRANSFER) {
+      // treat nested payloads as files
+      for (auto& file : payload.getNestedPayloads()) {

Review comment:
       Could this be const?

##########
File path: extensions/http-curl/tests/C2DebugBundleTest.cpp
##########
@@ -0,0 +1,205 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#undef NDEBUG
+
+#include "TestBase.h"
+
+#include "c2/C2Agent.h"
+#include "protocols/RESTProtocol.h"
+#include "protocols/RESTSender.h"
+#include "HTTPIntegrationBase.h"
+#include "HTTPHandlers.h"
+#include "io/ArchiveStream.h"
+
+using std::literals::chrono_literals::operator""s;
+
+class VerifyDebugInfo : public VerifyC2Base {
+ public:
+  explicit VerifyDebugInfo(std::function<bool()> verify): 
verify_(std::move(verify)) {}
+
+  void testSetup() override {
+    LogTestController::getInstance().setTrace<minifi::c2::C2Agent>();
+    LogTestController::getInstance().setDebug<minifi::c2::RESTSender>();
+    LogTestController::getInstance().setDebug<minifi::c2::RESTProtocol>();
+    VerifyC2Base::testSetup();
+  }
+
+  void runAssertions() override {
+    assert(utils::verifyEventHappenedInPollTime(std::chrono::seconds(300), 
verify_));
+  }
+
+  void configureC2() override {
+    VerifyC2Base::configureC2();
+    configuration->set("nifi.c2.agent.heartbeat.period", "100");
+  }
+
+  std::function<bool()> verify_;
+};
+
+class C2DebugBundleHandler : public ServerAwareHandler {
+  static int field_found(const char* key, const char* filename, char* 
/*path*/, size_t /*pathlen*/, void* user_data) {

Review comment:
       Public functions should be listed first in the class definition 
according to core guidelines 
[NL.16](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Rl-order).

##########
File path: extensions/http-curl/tests/C2DebugBundleTest.cpp
##########
@@ -0,0 +1,205 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#undef NDEBUG
+
+#include "TestBase.h"
+
+#include "c2/C2Agent.h"
+#include "protocols/RESTProtocol.h"
+#include "protocols/RESTSender.h"
+#include "HTTPIntegrationBase.h"
+#include "HTTPHandlers.h"
+#include "io/ArchiveStream.h"
+
+using std::literals::chrono_literals::operator""s;
+
+class VerifyDebugInfo : public VerifyC2Base {
+ public:
+  explicit VerifyDebugInfo(std::function<bool()> verify): 
verify_(std::move(verify)) {}
+
+  void testSetup() override {
+    LogTestController::getInstance().setTrace<minifi::c2::C2Agent>();
+    LogTestController::getInstance().setDebug<minifi::c2::RESTSender>();
+    LogTestController::getInstance().setDebug<minifi::c2::RESTProtocol>();
+    VerifyC2Base::testSetup();
+  }
+
+  void runAssertions() override {
+    assert(utils::verifyEventHappenedInPollTime(std::chrono::seconds(300), 
verify_));
+  }
+
+  void configureC2() override {
+    VerifyC2Base::configureC2();
+    configuration->set("nifi.c2.agent.heartbeat.period", "100");
+  }
+
+  std::function<bool()> verify_;
+};
+
+class C2DebugBundleHandler : public ServerAwareHandler {
+  static int field_found(const char* key, const char* filename, char* 
/*path*/, size_t /*pathlen*/, void* user_data) {
+    auto& file_content = *static_cast<std::optional<std::string>*>(user_data);
+    if (!filename || std::string(filename) != "debug.tar.gz") {
+      throw std::runtime_error("Unknown form entry: " + std::string{key});
+    }
+    if (file_content) {
+      throw std::runtime_error("Debug archive has already been extracted: " + 
std::string{key});
+    }
+    return MG_FORM_FIELD_STORAGE_GET;
+  }
+  static int field_get(const char* /*key*/, const char* value, size_t 
valuelen, void* user_data) {
+    auto& file_content = *static_cast<std::optional<std::string>*>(user_data);
+    file_content = "";
+    (*file_content) += std::string(value, valuelen);
+    return MG_FORM_FIELD_HANDLE_GET;
+  }
+
+ public:
+  bool handlePost(CivetServer* /*server*/, struct mg_connection *conn) 
override {
+    std::optional<std::string> file_content;
+    mg_form_data_handler form_handler;
+    form_handler.field_found = field_found;
+    form_handler.field_get = field_get;
+    form_handler.user_data = &file_content;
+    mg_handle_form_request(conn, &form_handler);
+    assert(file_content);
+    {
+      std::lock_guard<std::mutex> lock(mtx_);
+      bundles_.push_back(std::move(*file_content));
+    }
+    mg_printf(conn, "HTTP/1.1 200 OK\r\nContent-Type: "
+                      "text/plain\r\nContent-Length: 0\r\nConnection: 
close\r\n\r\n");
+    return true;
+  }
+
+  std::vector<std::string> getBundles() {
+    std::lock_guard<std::mutex> lock(mtx_);
+    return bundles_;
+  }
+
+  std::mutex mtx_;
+  std::vector<std::string> bundles_;

Review comment:
       Could these be private?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to