martinzink commented on code in PR #1383:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1383#discussion_r954906708


##########
extensions/http-curl/tests/unit/ConnectionCountingServer.h:
##########
@@ -0,0 +1,149 @@
+/**
+ *
+ * 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.
+ */
+
+#pragma once
+
+#include <array>
+#include <vector>
+#include <string>
+#include <set>
+#include "CivetServer.h"
+
+namespace org::apache::nifi::minifi::extensions::curl::testing {
+
+namespace details {
+
+class NumberedMethodResponder : public CivetHandler {
+ public:
+  explicit NumberedMethodResponder(std::set<utils::SmallString<36>>& 
connections) : connections_(connections) {}
+
+  bool handleGet(CivetServer*, struct mg_connection* conn) override {
+    sendNumberedMessage("GET", conn);
+    return true;
+  }
+
+  bool handlePost(CivetServer*, struct mg_connection* conn) override {
+    sendNumberedMessage("POST", conn);
+    return true;
+  }
+
+  bool handlePut(CivetServer*, struct mg_connection* conn) override {
+    sendNumberedMessage("PUT", conn);
+    return true;
+  }
+
+  bool handleHead(CivetServer*, struct mg_connection* conn) override {
+    sendNumberedMessage("HEAD", conn);
+    return true;
+  }
+
+ private:
+  void sendNumberedMessage(std::string body, struct mg_connection* conn) {
+    saveConnectionId(conn);
+    body.append(std::to_string(response_id_));
+    mg_printf(conn, "HTTP/1.1 200 OK\r\n");
+    mg_printf(conn, "Content-length: %lu\r\n", body.length());
+    mg_printf(conn, "Response-number: %" PRIu64 "\r\n", response_id_);
+    mg_printf(conn, "\r\n");
+    mg_printf(conn, body.data(), body.length());
+    ++response_id_;
+  }
+
+  void saveConnectionId(struct mg_connection* conn) {
+    auto user_connection_data = 
reinterpret_cast<utils::SmallString<36>*>(mg_get_user_connection_data(conn));
+    connections_.emplace(*user_connection_data);
+  }
+
+  uint64_t response_id_ = 0;
+  std::set<utils::SmallString<36>>& connections_;
+};
+
+class ReverseBodyPostHandler : public CivetHandler {
+ public:
+  explicit ReverseBodyPostHandler(std::set<utils::SmallString<36>>& 
connections) : connections_(connections) {}
+
+  bool handlePost(CivetServer* /*server*/, struct mg_connection* conn) 
override {
+    saveConnectionId(conn);
+    std::vector<char> request_body;
+    request_body.reserve(2048);
+    size_t read_size = mg_read(conn, request_body.data(), 2048);

Review Comment:
   added in 
https://github.com/apache/nifi-minifi-cpp/pull/1383/commits/3f4aeec40af42fb9df1b15fbf0c2298664e77675#diff-49cbe304b911422ac56db05d81e536df1526f08edbe8a2d53aee8c34fa6fd3c3R86



-- 
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: issues-unsubscr...@nifi.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to