forked from boostorg/beast
Tidy up namespaces in examples
This commit is contained in:
@@ -13,6 +13,10 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
using tcp = boost::asio::ip::tcp; // from <boost/asio.hpp>
|
||||
namespace ssl = boost::asio::ssl; // from <boost/asio/ssl.hpp>
|
||||
namespace http = beast::http; // from <beast/http.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
// A helper for reporting errors
|
||||
@@ -28,8 +32,8 @@ int main()
|
||||
|
||||
// Normal boost::asio setup
|
||||
boost::asio::io_service ios;
|
||||
boost::asio::ip::tcp::resolver r{ios};
|
||||
boost::asio::ip::tcp::socket sock{ios};
|
||||
tcp::resolver r{ios};
|
||||
tcp::socket sock{ios};
|
||||
|
||||
// Look up the domain name
|
||||
std::string const host = "www.example.com";
|
||||
@@ -43,27 +47,27 @@ int main()
|
||||
return fail("connect", ec);
|
||||
|
||||
// Wrap the now-connected socket in an SSL stream
|
||||
boost::asio::ssl::context ctx{boost::asio::ssl::context::sslv23};
|
||||
boost::asio::ssl::stream<boost::asio::ip::tcp::socket&> stream{sock, ctx};
|
||||
stream.set_verify_mode(boost::asio::ssl::verify_none);
|
||||
ssl::context ctx{ssl::context::sslv23};
|
||||
ssl::stream<tcp::socket&> stream{sock, ctx};
|
||||
stream.set_verify_mode(ssl::verify_none);
|
||||
|
||||
// Perform SSL handshaking
|
||||
stream.handshake(boost::asio::ssl::stream_base::client, ec);
|
||||
stream.handshake(ssl::stream_base::client, ec);
|
||||
if(ec)
|
||||
return fail("handshake", ec);
|
||||
|
||||
// Set up an HTTP GET request message
|
||||
beast::http::request<beast::http::string_body> req;
|
||||
req.method(beast::http::verb::get);
|
||||
http::request<http::string_body> req;
|
||||
req.method(http::verb::get);
|
||||
req.target("/");
|
||||
req.version = 11;
|
||||
req.set(beast::http::field::host, host + ":" +
|
||||
req.set(http::field::host, host + ":" +
|
||||
boost::lexical_cast<std::string>(sock.remote_endpoint().port()));
|
||||
req.set(beast::http::field::user_agent, "Beast");
|
||||
req.set(http::field::user_agent, "Beast");
|
||||
req.prepare();
|
||||
|
||||
// Write the HTTP request to the remote host
|
||||
beast::http::write(stream, req, ec);
|
||||
http::write(stream, req, ec);
|
||||
if(ec)
|
||||
return fail("write", ec);
|
||||
|
||||
@@ -71,10 +75,10 @@ int main()
|
||||
beast::flat_buffer b;
|
||||
|
||||
// Declare a container to hold the response
|
||||
beast::http::response<beast::http::dynamic_body> res;
|
||||
http::response<http::dynamic_body> res;
|
||||
|
||||
// Read the response
|
||||
beast::http::read(stream, b, res, ec);
|
||||
http::read(stream, b, res, ec);
|
||||
if(ec)
|
||||
return fail("read", ec);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user