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/20 14:11:20 UTC
[GitHub] [nifi-minifi-cpp] fgerlits opened a new pull request, #1442: MINIFICPP-1952 InvokeHTTP POST/PUT should support large files
fgerlits opened a new pull request, #1442:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1442
https://issues.apache.org/jira/browse/MINIFICPP-1952
When doing POST/PUT in InvokeHTTP, read the flow file contents in chunks during the upload instead of reading the whole thing at once into memory.
The change to `catch.hpp` is not part of this pull request, but of #1441. That PR should be merged first, after which the `catch.hpp` change will disappear from this PR.
---
Thank you for submitting a contribution to Apache NiFi - MiNiFi C++.
In order to streamline the review of the contribution we ask you
to ensure the following steps have been taken:
### For all changes:
- [x] Is there a JIRA ticket associated with this PR? Is it referenced
in the commit message?
- [x] Does your PR title start with MINIFICPP-XXXX where XXXX is the JIRA number you are trying to resolve? Pay particular attention to the hyphen "-" character.
- [x] Has your PR been rebased against the latest commit within the target branch (typically main)?
- [x] Is your initial contribution a single, squashed commit?
### For code changes:
- [ ] If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under [ASF 2.0](http://www.apache.org/legal/resolved.html#category-a)?
- [ ] If applicable, have you updated the LICENSE file?
- [ ] If applicable, have you updated the NOTICE file?
### For documentation related changes:
- [ ] Have you ensured that format looks appropriate for the output in which it is rendered?
### Note:
Please ensure that once the PR is submitted, you check GitHub Actions CI results for build issues and submit an update to your PR as soon as possible.
--
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
[GitHub] [nifi-minifi-cpp] fgerlits commented on a diff in pull request #1442: MINIFICPP-1952 InvokeHTTP POST/PUT should support large files
Posted by GitBox <gi...@apache.org>.
fgerlits commented on code in PR #1442:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1442#discussion_r1000837700
##########
libminifi/src/utils/BaseHTTPClient.cpp:
##########
@@ -160,4 +160,118 @@ 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)
+ len = size;
+ memcpy(data, ptr, len);
+ pos += len;
+ seek(pos);
+ return len;
+ }
+ return 0;
+}
+
+size_t HTTPUploadByteArrayInputCallback::setPosition(int64_t offset) {
+ if (stop) {
+ return HTTPRequestResponse::SEEKFUNC_FAIL;
+ }
+ if (getBufferSize() <= static_cast<size_t>(offset)) {
+ return HTTPRequestResponse::SEEKFUNC_FAIL;
+ }
+ pos = offset;
+ seek(pos);
+ return HTTPRequestResponse::SEEKFUNC_OK;
+}
+
+size_t HTTPUploadStreamContentsCallback::getDataChunk(char *data, size_t size) {
+ logger_->log_trace("HTTPUploadStreamContentsCallback is asked for up to %zu bytes", size);
+
+ std::vector<std::byte> buffer(size);
+ size_t num_read = input_stream_->read(buffer);
+
+ if (io::isError(num_read)) {
+ logger_->log_error("Error reading the input stream in HTTPUploadStreamContentsCallback");
+ return 0;
+ }
+ logger_->log_debug("HTTPUploadStreamContentsCallback is returning %zu bytes", num_read);
+
+ gsl_Expects(num_read <= size);
+ memcpy(data, buffer.data(), num_read);
+ return num_read;
+}
+
+size_t HTTPUploadStreamContentsCallback::setPosition(int64_t offset) {
+ if (offset == 0) {
+ logger_->log_debug("HTTPUploadStreamContentsCallback is ignoring request to rewind to the beginning");
+ } else {
+ logger_->log_warn("HTTPUploadStreamContentsCallback is ignoring request to seek to position %" PRId64, offset);
+ }
+
+ return HTTPRequestResponse::SEEKFUNC_OK;
Review Comment:
Yeah, it's not clear to me when and why curl would call seek during an upload. One thing I've seen during testing was a call to `seek(0)` _after_ the upload; if this call returns `SEEKFUNC_FAIL` then the upload fails, but if I don't do anything just return `SEEKFUNC_OK` then it works fine.
What do you think we should do?
--
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
[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a diff in pull request #1442: MINIFICPP-1952 InvokeHTTP POST/PUT should support large files
Posted by GitBox <gi...@apache.org>.
adamdebreceni commented on code in PR #1442:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1442#discussion_r1000732048
##########
libminifi/src/utils/BaseHTTPClient.cpp:
##########
@@ -160,4 +160,118 @@ 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)
+ len = size;
+ memcpy(data, ptr, len);
+ pos += len;
+ seek(pos);
+ return len;
+ }
+ return 0;
+}
+
+size_t HTTPUploadByteArrayInputCallback::setPosition(int64_t offset) {
+ if (stop) {
+ return HTTPRequestResponse::SEEKFUNC_FAIL;
+ }
+ if (getBufferSize() <= static_cast<size_t>(offset)) {
+ return HTTPRequestResponse::SEEKFUNC_FAIL;
+ }
+ pos = offset;
+ seek(pos);
+ return HTTPRequestResponse::SEEKFUNC_OK;
+}
+
+size_t HTTPUploadStreamContentsCallback::getDataChunk(char *data, size_t size) {
+ logger_->log_trace("HTTPUploadStreamContentsCallback is asked for up to %zu bytes", size);
+
+ std::vector<std::byte> buffer(size);
+ size_t num_read = input_stream_->read(buffer);
Review Comment:
can't we read directly into `data`? might there be a requirement to not mess up `data` if we can't read the full size (or maybe on error)?
--
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
[GitHub] [nifi-minifi-cpp] fgerlits commented on a diff in pull request #1442: MINIFICPP-1952 InvokeHTTP POST/PUT should support large files
Posted by GitBox <gi...@apache.org>.
fgerlits commented on code in PR #1442:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1442#discussion_r1001638990
##########
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:
This is pre-existing code, I'd rather not change it in this pull request. I have added your suggestions to https://issues.apache.org/jira/browse/MINIFICPP-1971.
##########
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:
Also added to https://issues.apache.org/jira/browse/MINIFICPP-1971.
--
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
[GitHub] [nifi-minifi-cpp] fgerlits commented on a diff in pull request #1442: MINIFICPP-1952 InvokeHTTP POST/PUT should support large files
Posted by GitBox <gi...@apache.org>.
fgerlits commented on code in PR #1442:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1442#discussion_r1000831997
##########
libminifi/src/utils/BaseHTTPClient.cpp:
##########
@@ -160,4 +160,118 @@ 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)
+ len = size;
+ memcpy(data, ptr, len);
+ pos += len;
+ seek(pos);
+ return len;
+ }
+ return 0;
+}
+
+size_t HTTPUploadByteArrayInputCallback::setPosition(int64_t offset) {
+ if (stop) {
+ return HTTPRequestResponse::SEEKFUNC_FAIL;
+ }
+ if (getBufferSize() <= static_cast<size_t>(offset)) {
+ return HTTPRequestResponse::SEEKFUNC_FAIL;
+ }
+ pos = offset;
+ seek(pos);
+ return HTTPRequestResponse::SEEKFUNC_OK;
+}
+
+size_t HTTPUploadStreamContentsCallback::getDataChunk(char *data, size_t size) {
+ logger_->log_trace("HTTPUploadStreamContentsCallback is asked for up to %zu bytes", size);
+
+ std::vector<std::byte> buffer(size);
+ size_t num_read = input_stream_->read(buffer);
Review Comment:
I don't know if there is such a requirement. You're right, it's probably safe to read into the buffer directly. I'll change it.
--
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
[GitHub] [nifi-minifi-cpp] fgerlits commented on a diff in pull request #1442: MINIFICPP-1952 InvokeHTTP POST/PUT should support large files
Posted by GitBox <gi...@apache.org>.
fgerlits commented on code in PR #1442:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1442#discussion_r1000831997
##########
libminifi/src/utils/BaseHTTPClient.cpp:
##########
@@ -160,4 +160,118 @@ 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)
+ len = size;
+ memcpy(data, ptr, len);
+ pos += len;
+ seek(pos);
+ return len;
+ }
+ return 0;
+}
+
+size_t HTTPUploadByteArrayInputCallback::setPosition(int64_t offset) {
+ if (stop) {
+ return HTTPRequestResponse::SEEKFUNC_FAIL;
+ }
+ if (getBufferSize() <= static_cast<size_t>(offset)) {
+ return HTTPRequestResponse::SEEKFUNC_FAIL;
+ }
+ pos = offset;
+ seek(pos);
+ return HTTPRequestResponse::SEEKFUNC_OK;
+}
+
+size_t HTTPUploadStreamContentsCallback::getDataChunk(char *data, size_t size) {
+ logger_->log_trace("HTTPUploadStreamContentsCallback is asked for up to %zu bytes", size);
+
+ std::vector<std::byte> buffer(size);
+ size_t num_read = input_stream_->read(buffer);
Review Comment:
I don't know if there is such a requirement. You're right, it's probably safe to read into the buffer directly. I have changed it.
--
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
[GitHub] [nifi-minifi-cpp] fgerlits commented on a diff in pull request #1442: MINIFICPP-1952 InvokeHTTP POST/PUT should support large files
Posted by GitBox <gi...@apache.org>.
fgerlits commented on code in PR #1442:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1442#discussion_r1000814275
##########
libminifi/src/utils/BaseHTTPClient.cpp:
##########
@@ -160,4 +160,118 @@ 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)
+ len = size;
+ memcpy(data, ptr, len);
+ pos += len;
+ seek(pos);
+ return len;
+ }
+ return 0;
+}
+
+size_t HTTPUploadByteArrayInputCallback::setPosition(int64_t offset) {
+ if (stop) {
+ return HTTPRequestResponse::SEEKFUNC_FAIL;
+ }
+ if (getBufferSize() <= static_cast<size_t>(offset)) {
+ return HTTPRequestResponse::SEEKFUNC_FAIL;
Review Comment:
I don't know to what extent these seeks are actually used, but I agree on both counts, i.e that it should be `<` and that it should be in a separate PR. I think the whole `HTTPUploadCallback` thing should be cleaned up; this could be a part of that. Should I create a Jira for this?
--
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
[GitHub] [nifi-minifi-cpp] adam-markovics commented on a diff in pull request #1442: MINIFICPP-1952 InvokeHTTP POST/PUT should support large files
Posted by GitBox <gi...@apache.org>.
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
[GitHub] [nifi-minifi-cpp] szaszm closed pull request #1442: MINIFICPP-1952 InvokeHTTP POST/PUT should support large files
Posted by GitBox <gi...@apache.org>.
szaszm closed pull request #1442: MINIFICPP-1952 InvokeHTTP POST/PUT should support large files
URL: https://github.com/apache/nifi-minifi-cpp/pull/1442
--
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
[GitHub] [nifi-minifi-cpp] fgerlits commented on a diff in pull request #1442: MINIFICPP-1952 InvokeHTTP POST/PUT should support large files
Posted by GitBox <gi...@apache.org>.
fgerlits commented on code in PR #1442:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1442#discussion_r1001455375
##########
libminifi/src/utils/BaseHTTPClient.cpp:
##########
@@ -160,4 +160,118 @@ 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)
+ len = size;
+ memcpy(data, ptr, len);
+ pos += len;
+ seek(pos);
+ return len;
+ }
+ return 0;
+}
+
+size_t HTTPUploadByteArrayInputCallback::setPosition(int64_t offset) {
+ if (stop) {
+ return HTTPRequestResponse::SEEKFUNC_FAIL;
+ }
+ if (getBufferSize() <= static_cast<size_t>(offset)) {
+ return HTTPRequestResponse::SEEKFUNC_FAIL;
Review Comment:
https://issues.apache.org/jira/browse/MINIFICPP-1971
--
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
[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a diff in pull request #1442: MINIFICPP-1952 InvokeHTTP POST/PUT should support large files
Posted by GitBox <gi...@apache.org>.
adamdebreceni commented on code in PR #1442:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1442#discussion_r1001416441
##########
libminifi/src/utils/BaseHTTPClient.cpp:
##########
@@ -160,4 +160,118 @@ 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)
+ len = size;
+ memcpy(data, ptr, len);
+ pos += len;
+ seek(pos);
+ return len;
+ }
+ return 0;
+}
+
+size_t HTTPUploadByteArrayInputCallback::setPosition(int64_t offset) {
+ if (stop) {
+ return HTTPRequestResponse::SEEKFUNC_FAIL;
+ }
+ if (getBufferSize() <= static_cast<size_t>(offset)) {
+ return HTTPRequestResponse::SEEKFUNC_FAIL;
Review Comment:
yes a Jira would be great
--
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
[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a diff in pull request #1442: MINIFICPP-1952 InvokeHTTP POST/PUT should support large files
Posted by GitBox <gi...@apache.org>.
adamdebreceni commented on code in PR #1442:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1442#discussion_r1000739624
##########
libminifi/src/utils/BaseHTTPClient.cpp:
##########
@@ -160,4 +160,118 @@ 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)
+ len = size;
+ memcpy(data, ptr, len);
+ pos += len;
+ seek(pos);
+ return len;
+ }
+ return 0;
+}
+
+size_t HTTPUploadByteArrayInputCallback::setPosition(int64_t offset) {
+ if (stop) {
+ return HTTPRequestResponse::SEEKFUNC_FAIL;
+ }
+ if (getBufferSize() <= static_cast<size_t>(offset)) {
+ return HTTPRequestResponse::SEEKFUNC_FAIL;
+ }
+ pos = offset;
+ seek(pos);
+ return HTTPRequestResponse::SEEKFUNC_OK;
+}
+
+size_t HTTPUploadStreamContentsCallback::getDataChunk(char *data, size_t size) {
+ logger_->log_trace("HTTPUploadStreamContentsCallback is asked for up to %zu bytes", size);
+
+ std::vector<std::byte> buffer(size);
+ size_t num_read = input_stream_->read(buffer);
+
+ if (io::isError(num_read)) {
+ logger_->log_error("Error reading the input stream in HTTPUploadStreamContentsCallback");
+ return 0;
+ }
+ logger_->log_debug("HTTPUploadStreamContentsCallback is returning %zu bytes", num_read);
+
+ gsl_Expects(num_read <= size);
+ memcpy(data, buffer.data(), num_read);
+ return num_read;
+}
+
+size_t HTTPUploadStreamContentsCallback::setPosition(int64_t offset) {
+ if (offset == 0) {
+ logger_->log_debug("HTTPUploadStreamContentsCallback is ignoring request to rewind to the beginning");
+ } else {
+ logger_->log_warn("HTTPUploadStreamContentsCallback is ignoring request to seek to position %" PRId64, offset);
+ }
+
+ return HTTPRequestResponse::SEEKFUNC_OK;
Review Comment:
some streams (like `FileStream`) might properly support `seek`s, could not calling `seek` cause problems? (corrupted data, failed request etc.) should we return `SEEKFUNC_FAIL` here?
--
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
[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a diff in pull request #1442: MINIFICPP-1952 InvokeHTTP POST/PUT should support large files
Posted by GitBox <gi...@apache.org>.
adamdebreceni commented on code in PR #1442:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1442#discussion_r1000727271
##########
libminifi/src/utils/BaseHTTPClient.cpp:
##########
@@ -160,4 +160,118 @@ 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)
+ len = size;
+ memcpy(data, ptr, len);
+ pos += len;
+ seek(pos);
+ return len;
+ }
+ return 0;
+}
+
+size_t HTTPUploadByteArrayInputCallback::setPosition(int64_t offset) {
+ if (stop) {
+ return HTTPRequestResponse::SEEKFUNC_FAIL;
+ }
+ if (getBufferSize() <= static_cast<size_t>(offset)) {
+ return HTTPRequestResponse::SEEKFUNC_FAIL;
Review Comment:
I see that this is the same as the original version (so we shouldn't tinker with it in this PR), but do you think it is ok to fail a seek to the end of the buffer?
--
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
[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a diff in pull request #1442: MINIFICPP-1952 InvokeHTTP POST/PUT should support large files
Posted by GitBox <gi...@apache.org>.
adamdebreceni commented on code in PR #1442:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1442#discussion_r1001463400
##########
libminifi/src/utils/BaseHTTPClient.cpp:
##########
@@ -160,4 +160,118 @@ 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)
+ len = size;
+ memcpy(data, ptr, len);
+ pos += len;
+ seek(pos);
+ return len;
+ }
+ return 0;
+}
+
+size_t HTTPUploadByteArrayInputCallback::setPosition(int64_t offset) {
+ if (stop) {
+ return HTTPRequestResponse::SEEKFUNC_FAIL;
+ }
+ if (getBufferSize() <= static_cast<size_t>(offset)) {
+ return HTTPRequestResponse::SEEKFUNC_FAIL;
+ }
+ pos = offset;
+ seek(pos);
+ return HTTPRequestResponse::SEEKFUNC_OK;
+}
+
+size_t HTTPUploadStreamContentsCallback::getDataChunk(char *data, size_t size) {
+ logger_->log_trace("HTTPUploadStreamContentsCallback is asked for up to %zu bytes", size);
+
+ std::vector<std::byte> buffer(size);
+ size_t num_read = input_stream_->read(buffer);
+
+ if (io::isError(num_read)) {
+ logger_->log_error("Error reading the input stream in HTTPUploadStreamContentsCallback");
+ return 0;
+ }
+ logger_->log_debug("HTTPUploadStreamContentsCallback is returning %zu bytes", num_read);
+
+ gsl_Expects(num_read <= size);
+ memcpy(data, buffer.data(), num_read);
+ return num_read;
+}
+
+size_t HTTPUploadStreamContentsCallback::setPosition(int64_t offset) {
+ if (offset == 0) {
+ logger_->log_debug("HTTPUploadStreamContentsCallback is ignoring request to rewind to the beginning");
+ } else {
+ logger_->log_warn("HTTPUploadStreamContentsCallback is ignoring request to seek to position %" PRId64, offset);
+ }
+
+ return HTTPRequestResponse::SEEKFUNC_OK;
Review Comment:
I see you have added it to this jira (https://issues.apache.org/jira/browse/MINIFICPP-1971), we will investigate there
--
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