Merge branch 'httpc' into online
This commit is contained in:
commit
9a12f84ffa
@ -68,18 +68,55 @@ const ResultCode ERROR_CERT_ALREADY_SET = // 0xD8A0A03D
|
|||||||
// Splits URL into its components. Example: https://citra-emu.org:443/index.html
|
// Splits URL into its components. Example: https://citra-emu.org:443/index.html
|
||||||
// is_https: true; host: citra-emu.org; port: 443; path: /index.html
|
// is_https: true; host: citra-emu.org; port: 443; path: /index.html
|
||||||
static URLInfo SplitUrl(const std::string& url) {
|
static URLInfo SplitUrl(const std::string& url) {
|
||||||
constexpr u16 default_http_port = 80;
|
const std::string prefix = "://";
|
||||||
constexpr u16 default_https_port = 443;
|
constexpr int default_http_port = 80;
|
||||||
|
constexpr int default_https_port = 443;
|
||||||
|
|
||||||
const auto result = boost::urls::parse_uri(url);
|
std::string host;
|
||||||
const bool is_https = result->scheme_id() == boost::urls::scheme::https;
|
int port = -1;
|
||||||
const auto port = result->port_number();
|
std::string path;
|
||||||
const auto default_port = is_https ? default_https_port : default_http_port;
|
|
||||||
|
const auto scheme_end = url.find(prefix);
|
||||||
|
const auto prefix_end = scheme_end == std::string::npos ? 0 : scheme_end + prefix.length();
|
||||||
|
bool is_https = scheme_end != std::string::npos && url.starts_with("https");
|
||||||
|
const auto path_index = url.find("/", prefix_end);
|
||||||
|
|
||||||
|
if (path_index == std::string::npos) {
|
||||||
|
// If no path is specified after the host, set it to "/"
|
||||||
|
host = url.substr(prefix_end);
|
||||||
|
const auto port_start = host.find(":");
|
||||||
|
if (port_start != std::string::npos) {
|
||||||
|
std::string port_str = host.substr(port_start + 1);
|
||||||
|
host = host.substr(0, port_start);
|
||||||
|
char* pEnd = NULL;
|
||||||
|
port = std::strtol(port_str.c_str(), &pEnd, 10);
|
||||||
|
if (*pEnd) {
|
||||||
|
port = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
path = "/";
|
||||||
|
} else {
|
||||||
|
host = url.substr(prefix_end, path_index - prefix_end);
|
||||||
|
const auto port_start = host.find(":");
|
||||||
|
if (port_start != std::string::npos) {
|
||||||
|
std::string port_str = host.substr(port_start + 1);
|
||||||
|
host = host.substr(0, port_start);
|
||||||
|
char* pEnd = NULL;
|
||||||
|
port = std::strtol(port_str.c_str(), &pEnd, 10);
|
||||||
|
if (*pEnd) {
|
||||||
|
port = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
path = url.substr(path_index);
|
||||||
|
}
|
||||||
|
if (port == -1) {
|
||||||
|
port = is_https ? default_https_port : default_http_port;
|
||||||
|
}
|
||||||
return URLInfo{
|
return URLInfo{
|
||||||
.is_https = is_https,
|
.is_https = is_https,
|
||||||
.host = std::string{result->encoded_host()},
|
.host = host,
|
||||||
.port = port == 0 ? default_port : port,
|
.port = port,
|
||||||
.path = std::string{result->encoded_path()},
|
.path = path,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user