2016-05-07 17:06:46 -04:00
|
|
|
//
|
2017-02-06 20:07:03 -05:00
|
|
|
// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
|
2016-05-07 17:06:46 -04:00
|
|
|
//
|
|
|
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
//
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2016-04-29 06:04:40 -04:00
|
|
|
#include "urls_large_data.hpp"
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2016-06-20 10:53:31 -04:00
|
|
|
#include <beast/core/streambuf.hpp>
|
|
|
|
#include <beast/http.hpp>
|
2017-07-20 08:01:46 -07:00
|
|
|
#include <boost/asio.hpp>
|
2016-11-09 10:40:09 -05:00
|
|
|
#include <boost/lexical_cast.hpp>
|
2017-07-20 08:01:46 -07:00
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
using namespace beast::http;
|
|
|
|
using namespace boost::asio;
|
|
|
|
|
|
|
|
template<class String>
|
|
|
|
void
|
2016-05-04 17:27:50 -04:00
|
|
|
err(beast::error_code const& ec, String const& what)
|
2017-07-20 08:01:46 -07:00
|
|
|
{
|
|
|
|
std::cerr << what << ": " << ec.message() << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int, char const*[])
|
|
|
|
{
|
|
|
|
io_service ios;
|
|
|
|
for(auto const& host : urls_large_data())
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
ip::tcp::resolver r(ios);
|
|
|
|
auto it = r.resolve(
|
|
|
|
ip::tcp::resolver::query{host, "http"});
|
2016-06-20 10:53:31 -04:00
|
|
|
ip::tcp::socket sock(ios);
|
|
|
|
connect(sock, it);
|
|
|
|
auto ep = sock.remote_endpoint();
|
2016-10-09 06:34:35 -04:00
|
|
|
request<empty_body> req;
|
2016-05-07 15:18:22 -04:00
|
|
|
req.method = "GET";
|
|
|
|
req.url = "/";
|
|
|
|
req.version = 11;
|
2016-11-10 05:34:49 -05:00
|
|
|
req.fields.insert("Host", host + std::string(":") +
|
2016-11-09 10:40:09 -05:00
|
|
|
boost::lexical_cast<std::string>(ep.port()));
|
2016-11-10 05:34:49 -05:00
|
|
|
req.fields.insert("User-Agent", "beast/http");
|
2016-04-29 06:04:40 -04:00
|
|
|
prepare(req);
|
2016-06-20 10:53:31 -04:00
|
|
|
write(sock, req);
|
2016-10-09 06:34:35 -04:00
|
|
|
response<string_body> res;
|
2016-06-20 10:53:31 -04:00
|
|
|
streambuf sb;
|
|
|
|
beast::http::read(sock, sb, res);
|
|
|
|
std::cout << res;
|
2017-07-20 08:01:46 -07:00
|
|
|
}
|
2016-10-04 18:00:11 -04:00
|
|
|
catch(beast::system_error const& ec)
|
2017-07-20 08:01:46 -07:00
|
|
|
{
|
|
|
|
std::cerr << host << ": " << ec.what();
|
|
|
|
}
|
|
|
|
catch(...)
|
|
|
|
{
|
|
|
|
std::cerr << host << ": unknown exception" << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|