]>
git.proxmox.com Git - ceph.git/blob - ceph/src/Beast/examples/http_crawl.cpp
2 // Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
8 #include "urls_large_data.hpp"
10 #include <beast/core/streambuf.hpp>
11 #include <beast/http.hpp>
12 #include <boost/asio.hpp>
13 #include <boost/lexical_cast.hpp>
16 using namespace beast::http
;
17 using namespace boost::asio
;
19 template<class String
>
21 err(beast::error_code
const& ec
, String
const& what
)
23 std::cerr
<< what
<< ": " << ec
.message() << std::endl
;
26 int main(int, char const*[])
29 for(auto const& host
: urls_large_data())
33 ip::tcp::resolver
r(ios
);
35 ip::tcp::resolver::query
{host
, "http"});
36 ip::tcp::socket
sock(ios
);
38 auto ep
= sock
.remote_endpoint();
39 request
<string_body
> req
;
43 req
.fields
.insert("Host", host
+ std::string(":") +
44 boost::lexical_cast
<std::string
>(ep
.port()));
45 req
.fields
.insert("User-Agent", "beast/http");
48 response
<string_body
> res
;
50 beast::http::read(sock
, sb
, res
);
53 catch(beast::system_error
const& ec
)
55 std::cerr
<< host
<< ": " << ec
.what();
59 std::cerr
<< host
<< ": unknown exception" << std::endl
;