arpadboda commented on a change in pull request #1046:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1046#discussion_r618661909



##########
File path: libminifi/src/utils/HTTPClient.cpp
##########
@@ -15,8 +15,43 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-#include "utils/HTTPClient.h"
+#include <algorithm>
 #include <string>
+
+#include "utils/HTTPClient.h"
+#include "utils/StringUtils.h"
+
+namespace {
+
+constexpr const char* HTTP = "http://";;
+constexpr const char* HTTPS = "https://";;
+
+utils::optional<std::string> parseProtocol(const std::string& url_input) {
+  if (utils::StringUtils::startsWith(url_input, HTTP)) {
+    return HTTP;
+  } else if (utils::StringUtils::startsWith(url_input, HTTPS)) {
+    return HTTPS;
+  } else {
+    return {};
+  }
+}
+
+utils::optional<int> parsePortNumber(const std::string& port_string) {
+  try {
+    size_t pos;
+    int port = std::stoi(port_string, &pos);
+    if (pos == port_string.size()) {

Review comment:
       A safety trim before doing this?
   "432 " would not be parsed as a port because of the ending space, but 
debugging would be a nightmare.

##########
File path: libminifi/include/utils/HTTPClient.h
##########
@@ -362,10 +363,27 @@ class BaseHTTPClient {
   virtual inline bool matches(const std::string &value, const std::string 
&sregex) = 0;
 };
 
-extern std::string get_token(utils::BaseHTTPClient *client, std::string 
username, std::string password);
+std::string get_token(utils::BaseHTTPClient *client, std::string username, 
std::string password);
+
+class URL {

Review comment:
       I really like the strict typing for this instead of using string and 
port numbers! 




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

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


Reply via email to