89 static const std::regex re(
90 R"(^(?:(https?)://)?(?![^/]*@)((?:(?:25[0-5]|2[0-4]\d|1?\d{1,2})\.){3}(?:25[0-5]|2[0-4]\d|1?\d{1,2})|[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?(?:\.[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?)*)(?::([0-9]{1,5}))?([^?#]*)(\?[^#]*)?(?:#.*)?$)",
91 std::regex::ECMAScript | std::regex::icase);
94 if (std::regex_match(url, match, re)) {
101 const std::string& scheme = match[1].matched ? match[1].str() :
"http";
102 const std::string& host = match[2].str();
103 const uint16_t port = match[3].matched ?
static_cast<uint16_t>(std::stoi(match[3].str())) :
static_cast<uint16_t>(80);
104 const std::string& path = (match[4].matched ? match[4].str() :
"/");
105 const std::string& query = (match[5].matched ? match[5].str() :
"");
107 if (scheme ==
"http") {
110 LOG(ERROR) <<
"Scheme not valid: " << scheme;
113 LOG(ERROR) <<
"EventSource url not accepted: " << url;
120 if (!origin.empty() && origin.at(origin.length() - 1) ==
'/') {
124 if (!path.empty() && path.at(0) !=
'/') {
128 return EventSource(!origin.empty() ? origin + path : path);