Skip to content

Commit

Permalink
HTTP: don't crash for resolve errors
Browse files Browse the repository at this point in the history
  • Loading branch information
black-sliver committed Dec 2, 2023
1 parent b55e464 commit d5bb60b
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/http/http.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,12 @@ class HTTP {
if (strcasecmp(proto.c_str(), "https") == 0) {
if (port.empty()) port = "443";
resolver = new tcp::resolver(io_context);
auto endpoints = resolver->resolve(host, port);
asio::error_code ec;
auto endpoints = resolver->resolve(host, port, ec);
if (ec) {
std::cout << "HTTP: failed to resolve host: " << ec.message() << "\n";
return false;
}

asio::ssl::context ctx(asio::ssl::context::tlsv12_client);
ctx.set_options(asio::ssl::context::default_workarounds
Expand Down Expand Up @@ -183,7 +188,12 @@ class HTTP {
else if (strcasecmp(proto.c_str(), "http") == 0) {
if (port.empty()) port = "80";
resolver = new tcp::resolver(io_context);
auto endpoints = resolver->resolve(host, port);
asio::error_code ec;
auto endpoints = resolver->resolve(host, port, ec);
if (ec) {
std::cout << "HTTP: failed to resolve host: " << ec.message() << "\n";
return false;
}
c = new tcp_client(io_context, endpoints, request);
}
else {
Expand Down

0 comments on commit d5bb60b

Please sign in to comment.