nifi-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [nifi-minifi-cpp] arpadboda commented on a change in pull request #782: MINIFICPP-1217 - RPG should configure http client with reasonable tim…
Date Fri, 15 May 2020 10:56:16 GMT

arpadboda commented on a change in pull request #782:
URL: https://github.com/apache/nifi-minifi-cpp/pull/782#discussion_r425722041



##########
File path: extensions/http-curl/tests/HTTPUtils.h
##########
@@ -0,0 +1,107 @@
+/**
+ *
+ * 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.
+ */
+
+#ifndef NIFI_MINIFI_CPP_HTTPUTILS_H
+#define NIFI_MINIFI_CPP_HTTPUTILS_H
+
+#if defined(_WIN32) || __cplusplus > 201103L
+#include <regex>
+#else
+#include <regex.h>
+#endif
+
+/**
+This function, unfortunately, assumes that we're parsing http components of a local host.
On windows this is problematic
+so we convert localhost to our local hostname.
+  */
+inline bool parse_http_components(const std::string &url, std::string &port, std::string
&scheme, std::string &path) {
+
+#if (__cplusplus > 201103L) || defined(_WIN32)

Review comment:
       I know it's old code, but we have regexutils, you can use that here. As we touch it,
let's remove the ifdef magics.
   It wraps regex and regex.h to have a common (RAII) interface, exactly for these scenarios.


##########
File path: extensions/http-curl/client/HTTPClient.cpp
##########
@@ -330,6 +335,27 @@ void HTTPClient::set_request_method(const std::string method) {
   }
 }
 
+int HTTPClient::onProgress(void *clientp, curl_off_t dltotal, curl_off_t dlnow, curl_off_t
ultotal, curl_off_t ulnow){
+  HTTPClient& client = *(HTTPClient*)(clientp);
+  auto now = std::chrono::high_resolution_clock::now();
+  auto elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(now - client.progress_.last_transferred_);
+  if(dlnow != client.progress_.downloaded_data_ || ulnow != client.progress_.uploaded_data_){
+    // did transfer data
+    client.progress_.last_transferred_ = now;
+    client.progress_.downloaded_data_ = dlnow;
+    client.progress_.uploaded_data_ = ulnow;
+    return 0;
+  }
+  // did not transfer data
+  if(elapsed.count() > client.read_timeout_ms_.count()){

Review comment:
       I think linter would ask for some spaces here.

##########
File path: extensions/http-curl/client/HTTPClient.h
##########
@@ -222,6 +222,21 @@ class HTTPClient : public BaseHTTPClient, public core::Connectable {
       }
     }
   }
+ private:
+  static int onProgress(void *client, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal,
curl_off_t ulnow);
+
+  struct Progress{
+    std::chrono::high_resolution_clock::time_point last_transferred_;
+    curl_off_t uploaded_data_;
+    curl_off_t downloaded_data_;
+    void reset(){
+      last_transferred_ = std::chrono::high_resolution_clock::now();

Review comment:
       Is high res clock steady clock?
   Otherwise changes in system time or DST changes can make fun of us. 

##########
File path: extensions/http-curl/tests/HTTPHandlers.h
##########
@@ -85,7 +87,7 @@ class PeerResponder : public CivetHandler {
 #else
 	  std::string hostname = "localhost";
 #endif
-    std::string site2site_rest_resp = "{\"peers\" : [{ \"hostname\": \"" + hostname + "\",
\"port\": 8099,  \"secure\": false, \"flowFileCount\" : 0 }] }";
+    std::string site2site_rest_resp = "{\"peers\" : [{ \"hostname\": \"" + hostname + "\",
\"port\": " + port + ",  \"secure\": false, \"flowFileCount\" : 0 }] }";

Review comment:
       👍 




----------------------------------------------------------------
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:
users@infra.apache.org



Mime
View raw message