small rectorings
This commit is contained in:
@@ -76,10 +76,10 @@ void HttpClient::responseHeaders(const std::string &headers) {
|
||||
}
|
||||
}
|
||||
|
||||
int HttpClient::responseStatusCode(const std::string &status_str) const {
|
||||
int HttpClient::responseStatusCode(const std::string &status_str) {
|
||||
auto resp_status = 200; // default is OK
|
||||
|
||||
std::regex status_rgx{"^HTTP/\\d\\.\\d (\\d{3}) .+$"};
|
||||
std::regex status_rgx{R"(^HTTP/\d\.\d (\d{3}) .+$)"};
|
||||
std::smatch status_matches;
|
||||
if (std::regex_search(status_str, status_matches, status_rgx)) {
|
||||
if (status_matches.size() > 1)
|
||||
@@ -125,17 +125,19 @@ void HttpClient::parseURL(const std::string &url) {
|
||||
case 6:
|
||||
href = matches[i].str();
|
||||
break;
|
||||
default:
|
||||
std::cerr << "Unexpected part of url: " << url << std::endl;
|
||||
break;
|
||||
}
|
||||
// std::cout << i << ": '" << matches[i].str() << "'\n";
|
||||
}
|
||||
} else {
|
||||
std::cerr << "Match not found" << std::endl; // TODO better message
|
||||
std::cerr << "Cannot parse url: " << url << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
std::string HttpClient::inetAddress(const std::string &hostname) {
|
||||
hostent *record = gethostbyname(hostname.c_str());
|
||||
if (record == NULL) {
|
||||
if (record == nullptr) {
|
||||
throw std::runtime_error(hostname + " network unavailable.");
|
||||
}
|
||||
auto *address = (in_addr *) record->h_addr;
|
||||
@@ -202,7 +204,7 @@ int HttpClient::sslRequest(const std::string &server_name, const std::string &re
|
||||
|
||||
// socket address
|
||||
std::string server_ip = inetAddress(server_name);
|
||||
struct sockaddr_in sa;
|
||||
struct sockaddr_in sa{};
|
||||
memset(&sa, 0, sizeof(sa));
|
||||
sa.sin_family = AF_INET;
|
||||
sa.sin_addr.s_addr = inet_addr(server_ip.c_str());
|
||||
@@ -260,7 +262,7 @@ int HttpClient::sslRequest(const std::string &server_name, const std::string &re
|
||||
void HttpClient::logSSL() {
|
||||
unsigned long err;
|
||||
while ((err = ERR_get_error())) {
|
||||
char *str = ERR_error_string(err, 0);
|
||||
char *str = ERR_error_string(err, nullptr);
|
||||
if (!str)
|
||||
return;
|
||||
std::cerr << str << std::endl;
|
||||
|
||||
Reference in New Issue
Block a user