mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-04-28 11:47:48 +02:00
load host.txt via HTTPProxy
This commit is contained in:
parent
cdbcf0db76
commit
0c36925b87
4 changed files with 67 additions and 11 deletions
59
util.cpp
59
util.cpp
|
@ -248,6 +248,65 @@ namespace http
|
|||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
int httpRequestViaI2pProxy(const std::string& address, std::string &content)
|
||||
{
|
||||
content = "";
|
||||
try
|
||||
{
|
||||
boost::asio::ip::tcp::iostream site;
|
||||
// please don't uncomment following line because it's not compatible with boost 1.46
|
||||
// 1.46 is default boost for Ubuntu 12.04 LTS
|
||||
//site.expires_from_now (boost::posix_time::seconds(30));
|
||||
{
|
||||
std::stringstream ss; ss << i2p::util::config::GetArg("-httpproxyport", 4446);
|
||||
site.connect("127.0.0.1", ss.str());
|
||||
}
|
||||
if (site)
|
||||
{
|
||||
i2p::util::http::url u(address);
|
||||
std::stringstream ss;
|
||||
ss << "GET " << address << " HTTP/1.0" << std::endl;
|
||||
ss << "Host: " << u.host_ << std::endl;
|
||||
ss << "Accept: */*" << std::endl;
|
||||
ss << "User - Agent: Wget / 1.11.4" << std::endl;
|
||||
ss << "Connection: close" << std::endl;
|
||||
ss << std::endl;
|
||||
site << ss.str();
|
||||
|
||||
// read response
|
||||
std::string version, statusMessage;
|
||||
site >> version; // HTTP version
|
||||
int status;
|
||||
site >> status; // status
|
||||
std::getline(site, statusMessage);
|
||||
if (status == 200) // OK
|
||||
{
|
||||
std::string header;
|
||||
while (std::getline(site, header) && header != "\r"){}
|
||||
std::stringstream ss;
|
||||
ss << site.rdbuf();
|
||||
content = ss.str();
|
||||
return status;
|
||||
}
|
||||
else
|
||||
{
|
||||
LogPrint("HTTP response ", status);
|
||||
return status;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LogPrint("Can't connect to proxy");
|
||||
return 408;
|
||||
}
|
||||
}
|
||||
catch (std::exception& ex)
|
||||
{
|
||||
LogPrint("Failed to download ", address, " : ", ex.what());
|
||||
return 408;
|
||||
}
|
||||
}
|
||||
|
||||
url::url(const std::string& url_s)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue