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/04/29 09:40:50 UTC

[GitHub] [nifi-minifi-cpp] lordgamez opened a new pull request, #1321: MINIFICPP-1787 Add option to fix invalid attributes in HTTP header of InvokeHTTP

lordgamez opened a new pull request, #1321:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1321

   https://issues.apache.org/jira/browse/MINIFICPP-1787
   
   -------------------------------------------------
   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:
   - [ ] Is there a JIRA ticket associated with this PR? Is it referenced
        in the commit message?
   
   - [ ] 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.
   
   - [ ] Has your PR been rebased against the latest commit within the target branch (typically main)?
   
   - [ ] 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] lordgamez commented on a diff in pull request #1321: MINIFICPP-1787 Add option to handle invalid attributes in HTTP header of InvokeHTTP

Posted by GitBox <gi...@apache.org>.
lordgamez commented on code in PR #1321:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1321#discussion_r869048323


##########
extensions/http-curl/client/HTTPClient.cpp:
##########
@@ -455,6 +455,39 @@ void HTTPClient::setFollowRedirects(bool follow) {
   curl_easy_setopt(http_session_, CURLOPT_FOLLOWLOCATION, follow);
 }
 
+bool HTTPClient::isValidHTTPHeaderField(std::string_view field_name) {
+  if (field_name.size() == 0) {
+    return false;
+  }
+
+  // RFC822 3.1.2: The  field-name must be composed of printable ASCII characters
+  // (i.e., characters that  have  values  between  33.  and  126., decimal, except colon).
+  for (auto ch : field_name) {
+    if (ch < 33 || ch > 126 || ch == ':') {
+      return false;
+    }
+  }
+  return true;
+}
+
+std::string HTTPClient::replaceInvalidCharactersInHTTPHeaderFieldName(std::string_view field_name) {
+  if (field_name.size() == 0) {
+    return "";
+  }

Review Comment:
   I agree, it seems that empty attribute name is accepted, but in this case we should replace it to a valid name and "X-MiNiFi-Empty-Attribute-Name" sounds good. Updated in 2d58393dbbb46ec17e56b961e01f04e1be6880bb



-- 
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 #1321: MINIFICPP-1787 Add option to handle invalid attributes in HTTP header of InvokeHTTP

Posted by GitBox <gi...@apache.org>.
szaszm closed pull request #1321: MINIFICPP-1787 Add option to handle invalid attributes in HTTP header of InvokeHTTP
URL: https://github.com/apache/nifi-minifi-cpp/pull/1321


-- 
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 commented on a diff in pull request #1321: MINIFICPP-1787 Add option to handle invalid attributes in HTTP header of InvokeHTTP

Posted by GitBox <gi...@apache.org>.
szaszm commented on code in PR #1321:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1321#discussion_r868111368


##########
extensions/http-curl/processors/InvokeHTTP.cpp:
##########
@@ -115,6 +107,16 @@ core::Property InvokeHTTP::AlwaysOutputResponse("Always Output Response", "Will
 core::Property InvokeHTTP::PenalizeOnNoRetry("Penalize on \"No Retry\"", "Enabling this property will penalize FlowFiles that are routed to the \"No Retry\" relationship.", "false");
 
 core::Property InvokeHTTP::DisablePeerVerification("Disable Peer Verification", "Disables peer verification for the SSL session", "false");
+
+core::Property InvokeHTTP::InvalidHTTPHeaderFieldHandlingStrategy(
+    core::PropertyBuilder::createProperty("Invalid HTTP Header Field Handling Strategy")
+      ->withDescription("Indicates what should happen when an attribute's name is not a valid HTTP header field name. "
+        "Options: fail - flow file is transferred to failure, transform - invalid characters are replaced, drop - drops invalid attributes from HTTP message")
+      ->isRequired(true)
+      ->withDefaultValue<std::string>(toString(InvalidHTTPHeaderFieldHandlingOption::FAIL))
+      ->withAllowableValues<std::string>(InvalidHTTPHeaderFieldHandlingOption::values())

Review Comment:
   Either of the other options is more useful than the FAIL. I would default to something else. Leaning towards transform, but drop is fine, too. 



##########
extensions/http-curl/client/HTTPClient.cpp:
##########
@@ -455,6 +455,39 @@ void HTTPClient::setFollowRedirects(bool follow) {
   curl_easy_setopt(http_session_, CURLOPT_FOLLOWLOCATION, follow);
 }
 
+bool HTTPClient::isValidHTTPHeaderField(std::string_view field_name) {
+  if (field_name.size() == 0) {
+    return false;
+  }
+
+  // RFC822 3.1.2: The  field-name must be composed of printable ASCII characters
+  // (i.e., characters that  have  values  between  33.  and  126., decimal, except colon).
+  for (auto ch : field_name) {
+    if (ch < 33 || ch > 126 || ch == ':') {
+      return false;
+    }
+  }
+  return true;
+}
+
+std::string HTTPClient::replaceInvalidCharactersInHTTPHeaderFieldName(std::string_view field_name) {
+  if (field_name.size() == 0) {
+    return "";
+  }

Review Comment:
   It might be better to limit the domain instead of extending the range. I would just say that the range (of return values) is a valid HTTP header field name. We should accept anything that we can transform into one, but an empty string is not one. Is it possible to have attributes with empty names? If so, maybe return a special name, like "X-MiNiFi-Empty-Attribute-Name".
   
   This doesn't apply to `isValidHTTPHeaderField`, because the range is the same there, so extending the domain strictly adds to the usefulness of the function.
   
   Please use one lowerCamelCase word even for acronyms, i.e. HTTP becomes Http. For now, I wouldn't change the class name, but I would name the new functions (including `isValidHTTPHeaderField`) accordingly.



-- 
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] lordgamez commented on a diff in pull request #1321: MINIFICPP-1787 Add option to handle invalid attributes in HTTP header of InvokeHTTP

Posted by GitBox <gi...@apache.org>.
lordgamez commented on code in PR #1321:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1321#discussion_r869048740


##########
extensions/http-curl/processors/InvokeHTTP.cpp:
##########
@@ -115,6 +107,16 @@ core::Property InvokeHTTP::AlwaysOutputResponse("Always Output Response", "Will
 core::Property InvokeHTTP::PenalizeOnNoRetry("Penalize on \"No Retry\"", "Enabling this property will penalize FlowFiles that are routed to the \"No Retry\" relationship.", "false");
 
 core::Property InvokeHTTP::DisablePeerVerification("Disable Peer Verification", "Disables peer verification for the SSL session", "false");
+
+core::Property InvokeHTTP::InvalidHTTPHeaderFieldHandlingStrategy(
+    core::PropertyBuilder::createProperty("Invalid HTTP Header Field Handling Strategy")
+      ->withDescription("Indicates what should happen when an attribute's name is not a valid HTTP header field name. "
+        "Options: fail - flow file is transferred to failure, transform - invalid characters are replaced, drop - drops invalid attributes from HTTP message")
+      ->isRequired(true)
+      ->withDefaultValue<std::string>(toString(InvalidHTTPHeaderFieldHandlingOption::FAIL))
+      ->withAllowableValues<std::string>(InvalidHTTPHeaderFieldHandlingOption::values())

Review Comment:
   I changed the default to `transform` in 2d58393dbbb46ec17e56b961e01f04e1be6880bb



-- 
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