forked from boostorg/beast
Documentation work
This commit is contained in:
1 parent
38c36ac655
commit
cff5be3837
31 files changed
+510
-353
No files matched your search
@@ -70,6 +70,7 @@ unit-test http-bench :
|
||||
|
||||
unit-test websocket-tests :
|
||||
../extras/beast/unit_test/main.cpp
|
||||
websocket/doc_snippets.cpp
|
||||
websocket/error.cpp
|
||||
websocket/option.cpp
|
||||
websocket/rfc6455.cpp
|
||||
|
||||
@@ -23,14 +23,14 @@ void fxx()
|
||||
|
||||
//[snippet_core_1b
|
||||
//
|
||||
using namespace beast;
|
||||
using namespace beast;
|
||||
|
||||
boost::asio::io_service ios;
|
||||
boost::asio::io_service::work work{ios};
|
||||
std::thread t{[&](){ ios.run(); }};
|
||||
boost::asio::io_service ios;
|
||||
boost::asio::io_service::work work{ios};
|
||||
std::thread t{[&](){ ios.run(); }};
|
||||
|
||||
error_code ec;
|
||||
boost::asio::ip::tcp::socket sock{ios};
|
||||
error_code ec;
|
||||
boost::asio::ip::tcp::socket sock{ios};
|
||||
|
||||
//]
|
||||
|
||||
|
||||
@@ -122,7 +122,6 @@ void fxx() {
|
||||
//[http_snippet_10
|
||||
|
||||
response<string_body> res;
|
||||
|
||||
serializer<false, string_body, fields> sr{res};
|
||||
|
||||
//]
|
||||
|
||||
+19
-19
@@ -74,63 +74,63 @@ public:
|
||||
testMessage()
|
||||
{
|
||||
BOOST_STATIC_ASSERT(std::is_constructible<
|
||||
message<true, default_body, fields>>::value);
|
||||
request<default_body>>::value);
|
||||
|
||||
BOOST_STATIC_ASSERT(std::is_constructible<
|
||||
message<true, one_arg_body, fields>, Arg1>::value);
|
||||
request<one_arg_body>, Arg1>::value);
|
||||
|
||||
BOOST_STATIC_ASSERT(std::is_constructible<
|
||||
message<true, one_arg_body, fields>, Arg1 const>::value);
|
||||
request<one_arg_body>, Arg1 const>::value);
|
||||
|
||||
BOOST_STATIC_ASSERT(std::is_constructible<
|
||||
message<true, one_arg_body, fields>, Arg1 const&>::value);
|
||||
request<one_arg_body>, Arg1 const&>::value);
|
||||
|
||||
BOOST_STATIC_ASSERT(std::is_constructible<
|
||||
message<true, one_arg_body, fields>, Arg1&&>::value);
|
||||
request<one_arg_body>, Arg1&&>::value);
|
||||
|
||||
BOOST_STATIC_ASSERT(! std::is_constructible<
|
||||
message<true, one_arg_body, fields>>::value);
|
||||
request<one_arg_body>>::value);
|
||||
|
||||
BOOST_STATIC_ASSERT(std::is_constructible<
|
||||
message<true, one_arg_body, fields>,
|
||||
request<one_arg_body>,
|
||||
Arg1, fields::allocator_type>::value);
|
||||
|
||||
BOOST_STATIC_ASSERT(std::is_constructible<
|
||||
message<true, one_arg_body, fields>, std::piecewise_construct_t,
|
||||
request<one_arg_body>, std::piecewise_construct_t,
|
||||
std::tuple<Arg1>>::value);
|
||||
|
||||
BOOST_STATIC_ASSERT(std::is_constructible<
|
||||
message<true, two_arg_body, fields>, std::piecewise_construct_t,
|
||||
request<two_arg_body>, std::piecewise_construct_t,
|
||||
std::tuple<Arg1, Arg2>>::value);
|
||||
|
||||
BOOST_STATIC_ASSERT(std::is_constructible<
|
||||
message<true, two_arg_body, fields>, std::piecewise_construct_t,
|
||||
request<two_arg_body>, std::piecewise_construct_t,
|
||||
std::tuple<Arg1, Arg2>, std::tuple<fields::allocator_type>>::value);
|
||||
|
||||
{
|
||||
Arg1 arg1;
|
||||
message<true, one_arg_body, fields>{std::move(arg1)};
|
||||
request<one_arg_body>{std::move(arg1)};
|
||||
BEAST_EXPECT(arg1.moved);
|
||||
}
|
||||
|
||||
{
|
||||
header<true, fields> h;
|
||||
header<true> h;
|
||||
h.insert(field::user_agent, "test");
|
||||
message<true, one_arg_body, fields> m{Arg1{}, h};
|
||||
request<one_arg_body> m{Arg1{}, h};
|
||||
BEAST_EXPECT(h["User-Agent"] == "test");
|
||||
BEAST_EXPECT(m["User-Agent"] == "test");
|
||||
}
|
||||
{
|
||||
header<true, fields> h;
|
||||
header<true> h;
|
||||
h.insert(field::user_agent, "test");
|
||||
message<true, one_arg_body, fields> m{Arg1{}, std::move(h)};
|
||||
request<one_arg_body> m{Arg1{}, std::move(h)};
|
||||
BEAST_EXPECT(! h.exists("User-Agent"));
|
||||
BEAST_EXPECT(m["User-Agent"] == "test");
|
||||
}
|
||||
|
||||
// swap
|
||||
message<true, string_body, fields> m1;
|
||||
message<true, string_body, fields> m2;
|
||||
request<string_body> m1;
|
||||
request<string_body> m2;
|
||||
m1.target("u");
|
||||
m1.body = "1";
|
||||
m1.insert("h", "v");
|
||||
@@ -197,8 +197,8 @@ public:
|
||||
void
|
||||
testSwap()
|
||||
{
|
||||
message<false, string_body, fields> m1;
|
||||
message<false, string_body, fields> m2;
|
||||
response<string_body> m1;
|
||||
response<string_body> m2;
|
||||
m1.result(status::ok);
|
||||
m1.version = 10;
|
||||
m1.body = "1";
|
||||
|
||||
+2
-2
@@ -336,7 +336,7 @@ public:
|
||||
"GET / HTTP/1.1\r\n\r\n"};
|
||||
BEAST_EXPECT(handler::count() == 0);
|
||||
multi_buffer b;
|
||||
message<true, dynamic_body, fields> m;
|
||||
request<dynamic_body> m;
|
||||
async_read(is, b, m, handler{});
|
||||
BEAST_EXPECT(handler::count() > 0);
|
||||
ios.stop();
|
||||
@@ -355,7 +355,7 @@ public:
|
||||
"GET / HTTP/1.1\r\n\r\n"};
|
||||
BEAST_EXPECT(handler::count() == 0);
|
||||
multi_buffer b;
|
||||
message<true, dynamic_body, fields> m;
|
||||
request<dynamic_body> m;
|
||||
async_read(is, b, m, handler{});
|
||||
BEAST_EXPECT(handler::count() > 0);
|
||||
}
|
||||
|
||||
+15
-15
@@ -289,7 +289,7 @@ public:
|
||||
testAsyncWrite(yield_context do_yield)
|
||||
{
|
||||
{
|
||||
message<false, string_body, fields> m;
|
||||
response<string_body> m;
|
||||
m.version = 10;
|
||||
m.result(status::ok);
|
||||
m.reason("OK");
|
||||
@@ -308,7 +308,7 @@ public:
|
||||
"*****");
|
||||
}
|
||||
{
|
||||
message<false, string_body, fields> m;
|
||||
response<string_body> m;
|
||||
m.version = 11;
|
||||
m.result(status::ok);
|
||||
m.reason("OK");
|
||||
@@ -341,7 +341,7 @@ public:
|
||||
test::fail_counter fc(n);
|
||||
test::fail_stream<
|
||||
test::string_ostream> fs(fc, ios_);
|
||||
message<true, fail_body, fields> m{fc};
|
||||
request<fail_body> m{fc};
|
||||
m.method(verb::get);
|
||||
m.target("/");
|
||||
m.version = 10;
|
||||
@@ -372,7 +372,7 @@ public:
|
||||
test::fail_counter fc(n);
|
||||
test::fail_stream<
|
||||
test::string_ostream> fs(fc, ios_);
|
||||
message<true, fail_body, fields> m{fc};
|
||||
request<fail_body> m{fc};
|
||||
m.method(verb::get);
|
||||
m.target("/");
|
||||
m.version = 10;
|
||||
@@ -405,7 +405,7 @@ public:
|
||||
test::fail_counter fc(n);
|
||||
test::fail_stream<
|
||||
test::string_ostream> fs(fc, ios_);
|
||||
message<true, fail_body, fields> m{fc};
|
||||
request<fail_body> m{fc};
|
||||
m.method(verb::get);
|
||||
m.target("/");
|
||||
m.version = 10;
|
||||
@@ -438,7 +438,7 @@ public:
|
||||
test::fail_counter fc(n);
|
||||
test::fail_stream<
|
||||
test::string_ostream> fs(fc, ios_);
|
||||
message<true, fail_body, fields> m{fc};
|
||||
request<fail_body> m{fc};
|
||||
m.method(verb::get);
|
||||
m.target("/");
|
||||
m.version = 10;
|
||||
@@ -466,7 +466,7 @@ public:
|
||||
test::fail_counter fc(n);
|
||||
test::fail_stream<
|
||||
test::string_ostream> fs(fc, ios_);
|
||||
message<true, fail_body, fields> m{fc};
|
||||
request<fail_body> m{fc};
|
||||
m.method(verb::get);
|
||||
m.target("/");
|
||||
m.version = 10;
|
||||
@@ -495,7 +495,7 @@ public:
|
||||
{
|
||||
// auto content-length HTTP/1.0
|
||||
{
|
||||
message<true, string_body, fields> m;
|
||||
request<string_body> m;
|
||||
m.method(verb::get);
|
||||
m.target("/");
|
||||
m.version = 10;
|
||||
@@ -512,7 +512,7 @@ public:
|
||||
}
|
||||
// no content-length HTTP/1.0
|
||||
{
|
||||
message<true, unsized_body, fields> m;
|
||||
request<unsized_body> m;
|
||||
m.method(verb::get);
|
||||
m.target("/");
|
||||
m.version = 10;
|
||||
@@ -532,7 +532,7 @@ public:
|
||||
}
|
||||
// auto content-length HTTP/1.1
|
||||
{
|
||||
message<true, string_body, fields> m;
|
||||
request<string_body> m;
|
||||
m.method(verb::get);
|
||||
m.target("/");
|
||||
m.version = 11;
|
||||
@@ -549,7 +549,7 @@ public:
|
||||
}
|
||||
// no content-length HTTP/1.1
|
||||
{
|
||||
message<true, unsized_body, fields> m;
|
||||
request<unsized_body> m;
|
||||
m.method(verb::get);
|
||||
m.target("/");
|
||||
m.version = 11;
|
||||
@@ -574,7 +574,7 @@ public:
|
||||
void test_std_ostream()
|
||||
{
|
||||
// Conversion to std::string via operator<<
|
||||
message<true, string_body, fields> m;
|
||||
request<string_body> m;
|
||||
m.method(verb::get);
|
||||
m.target("/");
|
||||
m.version = 11;
|
||||
@@ -604,7 +604,7 @@ public:
|
||||
boost::asio::io_service ios;
|
||||
test::string_ostream os{ios};
|
||||
BEAST_EXPECT(handler::count() == 0);
|
||||
message<true, string_body, fields> m;
|
||||
request<string_body> m;
|
||||
m.method(verb::get);
|
||||
m.version = 11;
|
||||
m.target("/");
|
||||
@@ -626,7 +626,7 @@ public:
|
||||
boost::asio::io_service ios;
|
||||
test::string_ostream is{ios};
|
||||
BEAST_EXPECT(handler::count() == 0);
|
||||
message<true, string_body, fields> m;
|
||||
request<string_body> m;
|
||||
m.method(verb::get);
|
||||
m.version = 11;
|
||||
m.target("/");
|
||||
@@ -708,7 +708,7 @@ public:
|
||||
test::pipe p{ios_};
|
||||
p.client.write_size(3);
|
||||
|
||||
message<false, Body, fields> m0;
|
||||
response<Body> m0;
|
||||
m0.version = 11;
|
||||
m0.result(status::ok);
|
||||
m0.reason("OK");
|
||||
|
||||
@@ -10,6 +10,7 @@ add_executable (websocket-tests
|
||||
../../extras/beast/unit_test/main.cpp
|
||||
websocket_async_echo_server.hpp
|
||||
websocket_sync_echo_server.hpp
|
||||
doc_snippets.cpp
|
||||
error.cpp
|
||||
option.cpp
|
||||
rfc6455.cpp
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
//
|
||||
// Copyright (c) 2013-2017 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)
|
||||
//
|
||||
|
||||
#include <beast/core.hpp>
|
||||
#include <boost/asio.hpp>
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
|
||||
using namespace beast;
|
||||
|
||||
//[ws_snippet_1
|
||||
#include <beast/websocket.hpp>
|
||||
using namespace beast::websocket;
|
||||
//]
|
||||
|
||||
namespace doc_ws_snippets {
|
||||
|
||||
void fxx() {
|
||||
|
||||
boost::asio::io_service ios;
|
||||
boost::asio::io_service::work work{ios};
|
||||
std::thread t{[&](){ ios.run(); }};
|
||||
error_code ec;
|
||||
boost::asio::ip::tcp::socket sock{ios};
|
||||
|
||||
{
|
||||
//[ws_snippet_2
|
||||
stream<boost::asio::ip::tcp::socket> ws{ios};
|
||||
//]
|
||||
}
|
||||
|
||||
{
|
||||
//[ws_snippet_3
|
||||
stream<boost::asio::ip::tcp::socket> ws{std::move(sock)};
|
||||
//]
|
||||
}
|
||||
|
||||
{
|
||||
//[ws_snippet_4
|
||||
stream<boost::asio::ip::tcp::socket&> ws{sock};
|
||||
//]
|
||||
|
||||
//[ws_snippet_5
|
||||
ws.next_layer().shutdown(boost::asio::ip::tcp::socket::shutdown_send);
|
||||
//]
|
||||
}
|
||||
|
||||
{
|
||||
//[ws_snippet_6
|
||||
std::string const host = "mywebapp.com";
|
||||
boost::asio::ip::tcp::resolver r{ios};
|
||||
stream<boost::asio::ip::tcp::socket> ws{ios};
|
||||
boost::asio::connect(ws.next_layer(),
|
||||
r.resolve(boost::asio::ip::tcp::resolver::query{host, "ws"}));
|
||||
//]
|
||||
}
|
||||
|
||||
{
|
||||
//[ws_snippet_7
|
||||
boost::asio::ip::tcp::acceptor acceptor{ios};
|
||||
stream<boost::asio::ip::tcp::socket> ws{acceptor.get_io_service()};
|
||||
acceptor.accept(ws.next_layer());
|
||||
//]
|
||||
}
|
||||
|
||||
} // fxx()
|
||||
|
||||
} // doc_ws_snippets
|
||||
@@ -11,6 +11,7 @@ add_executable (websocket-ssl-tests
|
||||
${BEAST_INCLUDES}
|
||||
${EXTRAS_INCLUDES}
|
||||
../../../extras/beast/unit_test/main.cpp
|
||||
doc_snippets.cpp
|
||||
websocket_async_ssl_echo_server.hpp
|
||||
ssl_server.cpp
|
||||
)
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
//
|
||||
// Copyright (c) 2013-2017 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)
|
||||
//
|
||||
|
||||
#include <beast/core.hpp>
|
||||
#include <beast/websocket.hpp>
|
||||
#include <boost/asio.hpp>
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
|
||||
using namespace beast;
|
||||
using namespace beast::websocket;
|
||||
|
||||
//[wss_snippet_1
|
||||
#include <beast/websocket/ssl.hpp>
|
||||
#include <boost/asio/ssl.hpp>
|
||||
//]
|
||||
|
||||
namespace doc_wss_snippets {
|
||||
|
||||
void fxx() {
|
||||
|
||||
boost::asio::io_service ios;
|
||||
boost::asio::io_service::work work{ios};
|
||||
std::thread t{[&](){ ios.run(); }};
|
||||
error_code ec;
|
||||
boost::asio::ip::tcp::socket sock{ios};
|
||||
|
||||
{
|
||||
//[wss_snippet_2
|
||||
boost::asio::ssl::context ctx{boost::asio::ssl::context::sslv23};
|
||||
stream<boost::asio::ssl::stream<boost::asio::ip::tcp::socket>> wss{ios, ctx};
|
||||
//]
|
||||
}
|
||||
|
||||
{
|
||||
//[wss_snippet_3
|
||||
boost::asio::ip::tcp::endpoint ep;
|
||||
boost::asio::ssl::context ctx{boost::asio::ssl::context::sslv23};
|
||||
stream<boost::asio::ssl::stream<boost::asio::ip::tcp::socket>> ws{ios, ctx};
|
||||
|
||||
// connect the underlying TCP/IP socket
|
||||
ws.next_layer().next_layer().connect(ep);
|
||||
|
||||
// perform SSL handshake
|
||||
ws.next_layer().handshake(boost::asio::ssl::stream_base::client);
|
||||
|
||||
// perform WebSocket handshake
|
||||
ws.handshake("localhost", "/");
|
||||
//]
|
||||
}
|
||||
|
||||
} // fxx()
|
||||
|
||||
} // doc_wss_snippets
|
||||
Reference in new issue
Block a user