szaszm commented on code in PR #1331:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1331#discussion_r873877749


##########
extensions/http-curl/processors/InvokeHTTP.cpp:
##########
@@ -264,18 +269,36 @@ bool InvokeHTTP::shouldEmitFlowFile() const {
   return ("POST" == method_ || "PUT" == method_ || "PATCH" == method_);
 }
 
-std::optional<std::map<std::string, std::string>> 
InvokeHTTP::validateAttributesAgainstHTTPHeaderRules(const 
std::map<std::string, std::string>& attributes) const {
-  std::map<std::string, std::string> result;
-  for (const auto& [attribute_name, attribute_value] : attributes) {
-    if (utils::HTTPClient::isValidHttpHeaderField(attribute_name)) {
-      result.emplace(attribute_name, attribute_value);
-    } else if (invalid_http_header_field_handling_strategy_ == 
InvalidHTTPHeaderFieldHandlingOption::TRANSFORM) {
-      
result.emplace(utils::HTTPClient::replaceInvalidCharactersInHttpHeaderFieldName(attribute_name),
 attribute_value);
-    } else if (invalid_http_header_field_handling_strategy_ == 
InvalidHTTPHeaderFieldHandlingOption::FAIL) {
-      return std::nullopt;
-    }
+/**
+ * Calls append_header with valid HTTP header keys, based on 
attributes_to_send_. Returns whether the flow file should be routed to Failure.
+ * @param flow_file
+ * @param append_header Callback to append HTTP header to the request
+ * @return Whether the flow file should be routed to failure
+ */
+bool InvokeHTTP::appendHeaders(const core::FlowFile& flow_file, 
/*std::invocable<std::string, std::string>*/ auto append_header) {
+  if (!attributes_to_send_) return true;
+  const auto key_fn = [](const std::pair<std::string, std::string>& pair) { 
return pair.first; };
+  const auto original_attributes = flow_file.getAttributes();
+  // non-const views, because otherwise it doesn't satisfy viewable_range, and 
transform would fail
+  ranges::viewable_range auto matching_attributes = original_attributes
+      | ranges::views::filter([this](const auto& key) { return 
utils::regexMatch(key, *attributes_to_send_); }, key_fn);
+  switch (invalid_http_header_field_handling_strategy_.value()) {
+    case InvalidHTTPHeaderFieldHandlingOption::FAIL:
+      if (ranges::any_of(original_attributes, 
std::not_fn(&utils::HTTPClient::isValidHttpHeaderField), key_fn)) return false;

Review Comment:
   I agree that it's strange and I only used the original to keep the old 
behavior after seeing the relevant test fail. I think the old buggy behavior 
(before #1321) was to fail on matching attributes only, but match everything by 
default.
   CC @lordgamez, do you think it's OK to change this to the matching 
attributes only?



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to