szaszm commented on a change in pull request #743: Minificpp 1169 - Simplify C2 
metrics collection and reporting
URL: https://github.com/apache/nifi-minifi-cpp/pull/743#discussion_r390456234
 
 

 ##########
 File path: extensions/http-curl/tests/HTTPHandlers.h
 ##########
 @@ -343,4 +345,104 @@ class DeleteTransactionResponder : public CivetHandler {
   std::string response_code;
 };
 
+class HeartbeatHandler : public CivetHandler {
+ public:
+  explicit HeartbeatHandler(bool isSecure)
+      : isSecure(isSecure) {
+  }
+
+  std::string readPost(struct mg_connection *conn) {
+    std::string response;
+    int blockSize = 1024 * sizeof(char), readBytes;
+
+    char buffer[1024];
+    while ((readBytes = mg_read(conn, buffer, blockSize)) > 0) {
+      response.append(buffer, 0, (readBytes / sizeof(char)));
+    }
+    return response;
+  }
+
+  void sendStopOperation(struct mg_connection *conn) {
+    std::string resp = "{\"operation\" : \"heartbeat\", 
\"requested_operations\" : [{ \"operationid\" : 41, \"operation\" : \"stop\", 
\"operand\" : \"invoke\"  }, "
+        "{ \"operationid\" : 42, \"operation\" : \"stop\", \"operand\" : 
\"FlowController\"  } ]}";
 
 Review comment:
   Using a raw string literal would be nice for hardcoded JSONs.
   We can use the preprocessor for concatenation of string literals.
   We can use char arrays to avoid heap allocations. I wish we had 
`std::string_view`.
   I'm not sure about wrapping and copy-initialization vs 
direct-list-initialization.
   ```cpp
   const char heartbeat_response[] = R"json({"operation": "heartbeat", 
"requested_operations: [)json"
       R"json({"operationid": 41, "operation": "stop", "operand": "invoke"}, 
)json"
       R"json({"operationid": 42, "operation": "stop", "operand": 
"FlowController"}]})json";
   const char heartbeat_response2[]{ R"json({"operation": "heartbeat", 
"requested_operations: [{"operationid": 41, "operation": "stop", "operand": 
"invoke"}, {"operationid": 42, "operation": "stop", "operand": 
"FlowController"}]})json" };
   const auto response_length = sizeof(heartbeat_response);
   ```

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to