MINIFICPP-460: InvokeHTTP should handle a missing content type gracefully This closes #302.
Signed off on github by achristianson Signed-off-by: Marc Parisi <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/repo Commit: http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/commit/18e87d2c Tree: http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/tree/18e87d2c Diff: http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/diff/18e87d2c Branch: refs/heads/master Commit: 18e87d2c18a136acfae3cc9b7f44cc95b62cf07a Parents: 4f9fcb7 Author: Marc Parisi <[email protected]> Authored: Wed Apr 18 15:00:23 2018 -0400 Committer: Marc Parisi <[email protected]> Committed: Thu Apr 19 19:30:21 2018 -0400 ---------------------------------------------------------------------- extensions/http-curl/processors/InvokeHTTP.cpp | 6 ++++-- extensions/http-curl/processors/InvokeHTTP.h | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/18e87d2c/extensions/http-curl/processors/InvokeHTTP.cpp ---------------------------------------------------------------------- diff --git a/extensions/http-curl/processors/InvokeHTTP.cpp b/extensions/http-curl/processors/InvokeHTTP.cpp index 6b501a8..feda511 100644 --- a/extensions/http-curl/processors/InvokeHTTP.cpp +++ b/extensions/http-curl/processors/InvokeHTTP.cpp @@ -52,6 +52,7 @@ namespace processors { std::shared_ptr<utils::IdGenerator> InvokeHTTP::id_generator_ = utils::IdGenerator::getIdGenerator(); const char *InvokeHTTP::ProcessorName = "InvokeHTTP"; +std::string InvokeHTTP::DefaultContentType = "application/octet-stream"; core::Property InvokeHTTP::Method("HTTP Method", "HTTP request method (GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS). " "Arbitrary methods are also supported. Methods other than POST, PUT and PATCH will be sent without a message body.", @@ -339,8 +340,9 @@ void InvokeHTTP::onTrigger(const std::shared_ptr<core::ProcessContext> &context, response_flow = std::static_pointer_cast<FlowFileRecord>(session->create()); } - std::string ct = content_type; - response_flow->addKeyedAttribute(MIME_TYPE, ct); + // if content type isn't returned we should return application/octet-stream + // as per RFC 2046 -- 4.5.1 + response_flow->addKeyedAttribute(MIME_TYPE, content_type ? std::string(content_type) : DefaultContentType); response_flow->addAttribute(STATUS_CODE, std::to_string(http_code)); if (response_headers.size() > 0) flowFile->addAttribute(STATUS_MESSAGE, response_headers.at(0)); http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/18e87d2c/extensions/http-curl/processors/InvokeHTTP.h ---------------------------------------------------------------------- diff --git a/extensions/http-curl/processors/InvokeHTTP.h b/extensions/http-curl/processors/InvokeHTTP.h index f1aff50..446cefe 100644 --- a/extensions/http-curl/processors/InvokeHTTP.h +++ b/extensions/http-curl/processors/InvokeHTTP.h @@ -20,6 +20,7 @@ #define __INVOKE_HTTP_H__ #include <memory> +#include <string> #include <regex> #include <curl/curl.h> @@ -67,6 +68,7 @@ class InvokeHTTP : public core::Processor { virtual ~InvokeHTTP(); // Processor Name static const char *ProcessorName; + static std::string DefaultContentType; // Supported Properties static core::Property Method; static core::Property URL;
