2016-05-07 17:06:46 -04:00
|
|
|
//
|
|
|
|
// Copyright (c) 2013-2016 Vinnie Falco (vinnie dot falco at gmail dot com)
|
|
|
|
//
|
|
|
|
// 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 "http_stream.hpp"
|
|
|
|
#include "urls_large_data.hpp"
|
2017-07-20 08:01:46 -07:00
|
|
|
|
|
|
|
#include <boost/asio.hpp>
|
|
|
|
#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"});
|
|
|
|
stream<ip::tcp::socket> hs(ios);
|
|
|
|
connect(hs.lowest_layer(), it);
|
|
|
|
auto ep = hs.lowest_layer().remote_endpoint();
|
2016-05-07 15:18:22 -04:00
|
|
|
request_v1<empty_body> req;
|
|
|
|
req.method = "GET";
|
|
|
|
req.url = "/";
|
|
|
|
req.version = 11;
|
2017-07-20 08:01:46 -07:00
|
|
|
req.headers.insert("Host", host +
|
|
|
|
std::string(":") + std::to_string(ep.port()));
|
|
|
|
req.headers.insert("User-Agent", "beast/http");
|
2016-04-29 06:04:40 -04:00
|
|
|
prepare(req);
|
2017-07-20 08:01:46 -07:00
|
|
|
hs.write(req);
|
2016-05-01 11:14:10 -04:00
|
|
|
response_v1<string_body> resp;
|
2017-07-20 08:01:46 -07:00
|
|
|
hs.read(resp);
|
|
|
|
std::cout << resp;
|
|
|
|
}
|
|
|
|
catch(boost::system::system_error const& ec)
|
|
|
|
{
|
|
|
|
std::cerr << host << ": " << ec.what();
|
|
|
|
}
|
|
|
|
catch(...)
|
|
|
|
{
|
|
|
|
std::cerr << host << ": unknown exception" << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|