|
|
|
@ -22,7 +22,7 @@ WSADATA wsaData;
@@ -22,7 +22,7 @@ WSADATA wsaData;
|
|
|
|
|
int iResult = WSAStartup(MAKEWORD(2, 2), &wsaData); |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
HTTPRequest::HTTPRequest(const std::shared_ptr<URI> u, const std::string &doc) { |
|
|
|
|
HTTPRequest::HTTPRequest(const std::shared_ptr<URI> u) { |
|
|
|
|
#ifdef WIN32 |
|
|
|
|
if (iResult != 0) { |
|
|
|
|
std::cout << "WSAStartup failed: " << iResult << std::endl; |
|
|
|
@ -30,7 +30,6 @@ HTTPRequest::HTTPRequest(const std::shared_ptr<URI> u, const std::string &doc) {
@@ -30,7 +30,6 @@ HTTPRequest::HTTPRequest(const std::shared_ptr<URI> u, const std::string &doc) {
|
|
|
|
|
} |
|
|
|
|
#endif |
|
|
|
|
uri = u; |
|
|
|
|
document = doc; |
|
|
|
|
version = Version::HTTP10; |
|
|
|
|
method = Method::GET; |
|
|
|
|
userAgent = "NetRunner"; |
|
|
|
@ -40,13 +39,14 @@ bool HTTPRequest::sendRequest(std::function<void(const HTTPResponse&)> responseC
@@ -40,13 +39,14 @@ bool HTTPRequest::sendRequest(std::function<void(const HTTPResponse&)> responseC
|
|
|
|
|
struct addrinfo hints; |
|
|
|
|
struct addrinfo *serverInfo = nullptr; |
|
|
|
|
std::string host = uri->authority.host; |
|
|
|
|
std::string document = uri->path; |
|
|
|
|
memset(&hints, 0, sizeof(hints)); |
|
|
|
|
hints.ai_family = AF_UNSPEC; |
|
|
|
|
hints.ai_socktype = SOCK_STREAM; |
|
|
|
|
hints.ai_flags = AI_PASSIVE; |
|
|
|
|
const int res = getaddrinfo(uri->authority.host.c_str(), std::to_string(uri->authority.port).c_str(), &hints, &serverInfo); |
|
|
|
|
if (res != 0) { |
|
|
|
|
std::cout << "Could not lookup " << uri->authority.host << ": " << res << std::endl; |
|
|
|
|
std::cout << "Could not lookup " << host << ": " << res << std::endl; |
|
|
|
|
freeaddrinfo(serverInfo); |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|