Skip to content

Commit

Permalink
debug
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathaniel Moschkin committed Feb 7, 2024
1 parent 4981524 commit 407eb05
Showing 1 changed file with 5 additions and 15 deletions.
20 changes: 5 additions & 15 deletions src/networkhelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,11 @@ ParsedURI parseURI(const std::string &url)
std::smatch match;
if (std::regex_match(url, match, PARSE_URL) && match.size() == 9) {
result.protocol = value_or(boost::algorithm::to_lower_copy(std::string(match[2])), "http");
std::cout << "Protocol: " << result.protocol << std::endl;
result.domain = match[3];
std::cout << "Domain: " << result.domain << std::endl;
const bool is_sequre_protocol = (result.protocol == "https" || result.protocol == "wss");
const bool is_sequre_protocol = (result.protocol == "https" || result.protocol == "wss");
result.port = value_or(match[5], (is_sequre_protocol) ? "443" : "80");
std::cout << "Port: " << result.port << std::endl;
result.resource = value_or(match[6], "/");
std::cout << "Resource: " << result.resource << std::endl;
result.query = match[8];
std::cout << "Query: " << result.query << std::endl;
assert(!result.domain.empty());
}
return result;
Expand Down Expand Up @@ -74,8 +69,7 @@ bool NetworkHelper::performRequest(boost::beast::http::request<boost::beast::htt
// Set some basic fields in the request
req.set(boost::beast::http::field::host, host);
req.set(boost::beast::http::field::user_agent, BOOST_BEAST_VERSION_STRING);

std::cout << "Raw Request: " << req << std::endl;

// Send the HTTP request to the remote host
boost::beast::http::write(stream, req);

Expand Down Expand Up @@ -117,18 +111,14 @@ bool NetworkHelper::performRequest(boost::beast::http::request<boost::beast::htt
bool NetworkHelper::downloadUrl(const std::string &url, std::function<bool(std::vector<uint8_t> &&)> lambda) noexcept
{
auto uri = parseURI(url);
uri.resource << "?" << uri.query;
std::cout << "Request downloadUrl: " << url << "\r\n";

std::string thisres;
thisres << uri.resource << "?" << uri.query;

http::request<http::string_body> req{http::verb::get, thisres, 11};
http::request<http::string_body> req{http::verb::get, uri.resource, 11};

// Declare a container to hold the response
http::response<http::vector_body<uint8_t>> res;
std::cout << "Perform Request, URI resource: " << uri.resource << std::endl;
std::cout << "Perform Request, raw URI: " << uri.domain.c_str() << std::endl;


if (!performRequest(req, res, uri.domain.c_str()))
return false;

Expand Down

0 comments on commit 407eb05

Please sign in to comment.