You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by GitBox <gi...@apache.org> on 2022/10/21 10:01:38 UTC

[GitHub] [nifi-minifi-cpp] adam-markovics commented on a diff in pull request #1442: MINIFICPP-1952 InvokeHTTP POST/PUT should support large files

adam-markovics commented on code in PR #1442:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1442#discussion_r1001608798


##########
libminifi/src/utils/BaseHTTPClient.cpp:
##########
@@ -160,4 +160,116 @@ std::string URL::toString() const {
   }
 }
 
+/**
+ * Receive HTTP Response.
+ */
+size_t HTTPRequestResponse::receiveWrite(char *data, size_t size, size_t nmemb, void *p) {
+  try {
+    if (p == nullptr) {
+      return CALLBACK_ABORT;
+    }
+    auto *callback = static_cast<HTTPReadCallback *>(p);
+    if (callback->stop) {
+      return CALLBACK_ABORT;
+    }
+    callback->write(data, (size * nmemb));
+    return (size * nmemb);
+  } catch (...) {
+    return CALLBACK_ABORT;
+  }
+}
+
+/**
+ * Callback for post, put, and patch operations
+ * @param data output buffer to write to
+ * @param size number of elements to write
+ * @param nmemb size of each element to write
+ * @param p input object to read from
+ */
+size_t HTTPRequestResponse::send_write(char *data, size_t size, size_t nmemb, void *p) {
+  try {
+    if (p == nullptr) {
+      return CALLBACK_ABORT;
+    }
+    auto *callback = reinterpret_cast<HTTPUploadCallback *>(p);
+    return callback->getDataChunk(data, size * nmemb);
+  } catch (...) {
+    return CALLBACK_ABORT;
+  }
+}
+
+int HTTPRequestResponse::seek_callback(void *p, int64_t offset, int) {
+  try {
+    if (p == nullptr) {
+      return SEEKFUNC_FAIL;
+    }
+    auto *callback = reinterpret_cast<HTTPUploadCallback *>(p);
+    return callback->setPosition(offset);
+  } catch (...) {
+    return SEEKFUNC_FAIL;
+  }
+}
+
+size_t HTTPUploadByteArrayInputCallback::getDataChunk(char *data, size_t size) {
+  if (stop) {
+    return HTTPRequestResponse::CALLBACK_ABORT;
+  }
+  size_t buffer_size = getBufferSize();
+  if (pos <= buffer_size) {
+    size_t len = buffer_size - pos;
+    if (len <= 0) {
+      return 0;
+    }
+    auto *ptr = getBuffer(pos);
+
+    if (ptr == nullptr) {
+      return 0;
+    }
+    if (len > size)

Review Comment:
   I would use `std::min` instead



##########
libminifi/src/utils/BaseHTTPClient.cpp:
##########
@@ -160,4 +160,116 @@ std::string URL::toString() const {
   }
 }
 
+/**
+ * Receive HTTP Response.
+ */
+size_t HTTPRequestResponse::receiveWrite(char *data, size_t size, size_t nmemb, void *p) {
+  try {
+    if (p == nullptr) {
+      return CALLBACK_ABORT;
+    }
+    auto *callback = static_cast<HTTPReadCallback *>(p);
+    if (callback->stop) {
+      return CALLBACK_ABORT;
+    }
+    callback->write(data, (size * nmemb));
+    return (size * nmemb);
+  } catch (...) {
+    return CALLBACK_ABORT;
+  }
+}
+
+/**
+ * Callback for post, put, and patch operations
+ * @param data output buffer to write to
+ * @param size number of elements to write
+ * @param nmemb size of each element to write
+ * @param p input object to read from
+ */
+size_t HTTPRequestResponse::send_write(char *data, size_t size, size_t nmemb, void *p) {
+  try {
+    if (p == nullptr) {
+      return CALLBACK_ABORT;
+    }
+    auto *callback = reinterpret_cast<HTTPUploadCallback *>(p);
+    return callback->getDataChunk(data, size * nmemb);
+  } catch (...) {
+    return CALLBACK_ABORT;
+  }
+}
+
+int HTTPRequestResponse::seek_callback(void *p, int64_t offset, int) {
+  try {
+    if (p == nullptr) {
+      return SEEKFUNC_FAIL;
+    }
+    auto *callback = reinterpret_cast<HTTPUploadCallback *>(p);
+    return callback->setPosition(offset);
+  } catch (...) {
+    return SEEKFUNC_FAIL;
+  }
+}
+
+size_t HTTPUploadByteArrayInputCallback::getDataChunk(char *data, size_t size) {
+  if (stop) {
+    return HTTPRequestResponse::CALLBACK_ABORT;
+  }
+  size_t buffer_size = getBufferSize();
+  if (pos <= buffer_size) {
+    size_t len = buffer_size - pos;
+    if (len <= 0) {

Review Comment:
   < is not possible, only ==
   Could be omitted if the enclosing `if` is modified to
   `if (pos < buffer_size) {`



-- 
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-unsubscribe@nifi.apache.org

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