| 92 | // --- URL utilities --- |
| 93 | |
| 94 | bool parse_url(const std::string &url, ParsedUrl &out) { |
| 95 | const std::wstring wurl = _s2wstring(url); |
| 96 | URL_COMPONENTS parts = {}; |
| 97 | parts.dwStructSize = sizeof(parts); |
| 98 | parts.dwSchemeLength = (DWORD)-1; |
| 99 | parts.dwHostNameLength = (DWORD)-1; |
| 100 | parts.dwUrlPathLength = (DWORD)-1; |
| 101 | parts.dwExtraInfoLength = (DWORD)-1; |
| 102 | if (!WinHttpCrackUrl(wurl.c_str(), 0, 0, &parts)) { |
| 103 | return false; |
| 104 | } |
| 105 | out.secure = (parts.nScheme == INTERNET_SCHEME_HTTPS); |
| 106 | out.port = parts.nPort; |
| 107 | out.host.assign(parts.lpszHostName, parts.dwHostNameLength); |
| 108 | out.path.assign(parts.lpszUrlPath, parts.dwUrlPathLength); |
| 109 | if (parts.dwExtraInfoLength > 0) { |
| 110 | out.path.append(parts.lpszExtraInfo, parts.dwExtraInfoLength); |
| 111 | } |
| 112 | if (out.path.empty()) { |
| 113 | out.path = L"/"; |
| 114 | } |
| 115 | return !out.host.empty(); |
| 116 | } |
| 117 | |
| 118 | bool normalize_endpoint(std::string &endpoint, const char *default_path_suffix) { |
| 119 | ParsedUrl parsed; |
no test coverage detected