| 49 | } |
| 50 | |
| 51 | void parse_url(const std::string *url, std::string *host, int *port, std::string *protocol) { |
| 52 | static std::string http("http://"); |
| 53 | static std::string https("https://"); |
| 54 | |
| 55 | if (url->compare(0, http.size(), http) == 0) |
| 56 | *protocol = http; |
| 57 | |
| 58 | if (url->compare(0, https.size(), https) == 0) |
| 59 | *protocol = https; |
| 60 | |
| 61 | if (!protocol->empty()) { |
| 62 | size_t pos = url->find_first_of(":", protocol->size()); |
| 63 | |
| 64 | if (pos == std::string::npos) { |
| 65 | pos = url->size(); |
| 66 | } |
| 67 | |
| 68 | *host = url->substr(protocol->size(), pos - protocol->size()); |
| 69 | |
| 70 | if (pos < url->size() && (*url)[pos] == ':') { |
| 71 | size_t ppos = url->find_first_of("/", pos); |
| 72 | if (ppos == std::string::npos) { |
| 73 | ppos = url->size(); |
| 74 | } |
| 75 | std::string portStr(url->substr(pos + 1, ppos - pos - 1)); |
| 76 | if (portStr.size() > 0) { |
| 77 | *port = std::stoi(portStr); |
| 78 | } |
| 79 | } else { |
| 80 | // In case the host contains no port, the first part is needed only |
| 81 | // For eg.: nifi.io/nifi |
| 82 | size_t ppos = host->find_first_of("/"); |
| 83 | if (ppos != std::string::npos) { |
| 84 | *host = host->substr(0, ppos); |
| 85 | } |
| 86 | } |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | void parse_url(const std::string *url, std::string *host, int *port, std::string *protocol, std::string *path, std::string *query) { |
| 91 | int temp_port = -1; |