///////////////////////////////////////////////////////
| 300 | |
| 301 | //////////////////////////////////////////////////////////// |
| 302 | bool Http::setHost(const std::string& host, unsigned short port, std::optional<IpAddress::Type> addressType) |
| 303 | { |
| 304 | // Check the protocol |
| 305 | if (toLower(host.substr(0, 7)) == "http://") |
| 306 | { |
| 307 | // HTTP protocol |
| 308 | m_hostName = host.substr(7); |
| 309 | m_port = (port != 0 ? port : 80); |
| 310 | } |
| 311 | else if (toLower(host.substr(0, 8)) == "https://") |
| 312 | { |
| 313 | // HTTPS protocol |
| 314 | m_hostName = host.substr(8); |
| 315 | m_port = (port != 0 ? port : 443); |
| 316 | m_https = true; |
| 317 | } |
| 318 | else |
| 319 | { |
| 320 | // Undefined protocol - use HTTP |
| 321 | m_hostName = host; |
| 322 | m_port = (port != 0 ? port : 80); |
| 323 | } |
| 324 | |
| 325 | // Remove any trailing '/' from the host name |
| 326 | if (!m_hostName.empty() && (*m_hostName.rbegin() == '/')) |
| 327 | m_hostName.erase(m_hostName.size() - 1); |
| 328 | |
| 329 | m_hosts = Dns::resolve(m_hostName).value_or(decltype(m_hosts){}); |
| 330 | m_addressType = addressType; |
| 331 | |
| 332 | return !m_hosts.empty(); |
| 333 | } |
| 334 | |
| 335 | |
| 336 | //////////////////////////////////////////////////////////// |
no test coverage detected