diff --git a/src/WebResource.cpp b/src/WebResource.cpp index 91de36bdab0b9c4cde1786b5582d45ceecb86306..73714ef192a47f68996ca43684308d764a52caaf 100644 --- a/src/WebResource.cpp +++ b/src/WebResource.cpp @@ -76,7 +76,7 @@ WebResource getLocalWebResource(std::string fileName) { WebResource getOnlineWebResource(std::string url) { std::shared_ptr<URI> uri = parseUri(url); - HTTPRequest request (uri, getDocumentFromURL(url)); + HTTPRequest request (uri); WebResource returnRes; request.sendRequest([&](HTTPResponse const& response){ diff --git a/src/main.cpp b/src/main.cpp index 40013619b0cb6f0251c9d5efe352d92aa5d90bda..3926aeee000ddba8ffce1257e5f93a0d55a6761b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -84,7 +84,7 @@ void navTo(std::string url) { std::shared_ptr<Node> rootNode = std::make_shared<Node>(NodeType::ROOT); window->setDOM(rootNode); std::shared_ptr<URI> uri = parseUri(url); - const std::shared_ptr<HTTPRequest> request = std::make_shared<HTTPRequest>(uri, getDocumentFromURL(url)); + const std::shared_ptr<HTTPRequest> request = std::make_shared<HTTPRequest>(uri); currentURL=url; request->sendRequest(handleRequest); } @@ -116,7 +116,7 @@ void handleRequest(const HTTPResponse &response) { } std::cout << "Redirect To: " << location << std::endl; std::shared_ptr<URI> uri = parseUri(location); - const std::unique_ptr<HTTPRequest> request = std::make_unique<HTTPRequest>(uri, getDocumentFromURL(location)); + const std::unique_ptr<HTTPRequest> request = std::make_unique<HTTPRequest>(uri); request->sendRequest(handleRequest); return; } diff --git a/src/networking/HTTPRequest.cpp b/src/networking/HTTPRequest.cpp index be7c78328b9c882f655312000061eb35676d56f2..d31195fbbd4894deb2a62f7e778a7e57d9791698 100644 --- a/src/networking/HTTPRequest.cpp +++ b/src/networking/HTTPRequest.cpp @@ -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) { } #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 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; } diff --git a/src/networking/HTTPRequest.h b/src/networking/HTTPRequest.h index bd4506c79f7e98ca5d0cf47b998a55e371cc4e28..c2d2c1e9aee8fd2cf00098dd60e1087eac919d2c 100644 --- a/src/networking/HTTPRequest.h +++ b/src/networking/HTTPRequest.h @@ -18,12 +18,11 @@ enum class Method { class HTTPRequest { public: - HTTPRequest(const std::shared_ptr<URI> u, const std::string &doc); + HTTPRequest(const std::shared_ptr<URI> u); bool sendRequest(std::function<void(const HTTPResponse&)> responseCallback) const; const std::string versionToString(const Version version) const; const std::string methodToString(const Method method) const; private: - std::string document; Version version; Method method; std::string userAgent; diff --git a/src/networking/URI.cpp b/src/networking/URI.cpp index 68acdff6aadc0e829369f5419dd92aae1ad1470e..892b91cb9ad1604e26ec9f783307a53336403381 100644 --- a/src/networking/URI.cpp +++ b/src/networking/URI.cpp @@ -71,7 +71,7 @@ std::unique_ptr<URI> parseUri(std::string raw) { last = cursor + 1; state = AUTHORITY; } else { - // TODO Handle this, URI can have only one slash + // TODO Handle this, URI may have only one slash } } else if (state == AUTHORITY) { /* At this point, this could either be the semi colon for