mirror of
https://github.com/boostorg/beast.git
synced 2025-07-29 20:37:31 +02:00
@ -1,6 +1,7 @@
|
||||
Version 131:
|
||||
|
||||
* basic_fields returns const values
|
||||
* Set SNI hostname in example SSL clients
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include <boost/beast/version.hpp>
|
||||
#include <boost/asio/connect.hpp>
|
||||
#include <boost/asio/ip/tcp.hpp>
|
||||
#include <boost/asio/ssl/error.hpp>
|
||||
#include <boost/asio/ssl/stream.hpp>
|
||||
#include <cstdlib>
|
||||
#include <functional>
|
||||
@ -66,6 +67,14 @@ public:
|
||||
char const* target,
|
||||
int version)
|
||||
{
|
||||
// Set SNI Hostname (many hosts need this to handshake successfully)
|
||||
if(! SSL_set_tlsext_host_name(stream_.native_handle(), host))
|
||||
{
|
||||
boost::system::error_code ec{static_cast<int>(::ERR_get_error()), boost::asio::error::get_ssl_category()};
|
||||
std::cerr << ec.message() << "\n";
|
||||
return;
|
||||
}
|
||||
|
||||
// Set up an HTTP GET request message
|
||||
req_.version(version);
|
||||
req_.method(http::verb::get);
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include <boost/asio/connect.hpp>
|
||||
#include <boost/asio/spawn.hpp>
|
||||
#include <boost/asio/ip/tcp.hpp>
|
||||
#include <boost/asio/ssl/error.hpp>
|
||||
#include <boost/asio/ssl/stream.hpp>
|
||||
#include <cstdlib>
|
||||
#include <functional>
|
||||
@ -57,6 +58,14 @@ do_session(
|
||||
tcp::resolver resolver{ioc};
|
||||
ssl::stream<tcp::socket> stream{ioc, ctx};
|
||||
|
||||
// Set SNI Hostname (many hosts need this to handshake successfully)
|
||||
if(! SSL_set_tlsext_host_name(stream.native_handle(), host.c_str()))
|
||||
{
|
||||
ec.assign(static_cast<int>(::ERR_get_error()), boost::asio::error::get_ssl_category());
|
||||
std::cerr << ec.message() << "\n";
|
||||
return;
|
||||
}
|
||||
|
||||
// Look up the domain name
|
||||
auto const results = resolver.async_resolve(host, port, yield[ec]);
|
||||
if(ec)
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include <boost/beast/version.hpp>
|
||||
#include <boost/asio/connect.hpp>
|
||||
#include <boost/asio/ip/tcp.hpp>
|
||||
#include <boost/asio/ssl/error.hpp>
|
||||
#include <boost/asio/ssl/stream.hpp>
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
@ -62,6 +63,13 @@ int main(int argc, char** argv)
|
||||
tcp::resolver resolver{ioc};
|
||||
ssl::stream<tcp::socket> stream{ioc, ctx};
|
||||
|
||||
// Set SNI Hostname (many hosts need this to handshake successfully)
|
||||
if(! SSL_set_tlsext_host_name(stream.native_handle(), host))
|
||||
{
|
||||
boost::system::error_code ec{static_cast<int>(::ERR_get_error()), boost::asio::error::get_ssl_category()};
|
||||
throw boost::system::system_error{ec};
|
||||
}
|
||||
|
||||
// Look up the domain name
|
||||
auto const results = resolver.resolve(host, port);
|
||||
|
||||
|
Reference in New Issue
Block a user