forked from boostorg/beast
Documentation work
This commit is contained in:
1 parent
b49b23ee83
commit
44995bf071
46 files changed
+1264
-153
No files matched your search
@@ -25,6 +25,7 @@ unit-test core-tests :
|
||||
core/buffers_adapter.cpp
|
||||
core/clamp.cpp
|
||||
core/consuming_buffers.cpp
|
||||
core/doc_core_samples.cpp
|
||||
core/doc_snippets.cpp
|
||||
core/error.cpp
|
||||
core/flat_buffer.cpp
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
# Part of Beast
|
||||
|
||||
GroupSources(examples examples)
|
||||
GroupSources(extras/beast extras)
|
||||
GroupSources(include/beast beast)
|
||||
GroupSources(test/core "/")
|
||||
|
||||
add_executable (core-tests
|
||||
${BEAST_INCLUDES}
|
||||
${EXAMPLES_INCLUDES}
|
||||
${EXTRAS_INCLUDES}
|
||||
../../extras/beast/unit_test/main.cpp
|
||||
async_result.cpp
|
||||
@@ -18,6 +20,7 @@ add_executable (core-tests
|
||||
buffers_adapter.cpp
|
||||
clamp.cpp
|
||||
consuming_buffers.cpp
|
||||
doc_core_samples.cpp
|
||||
doc_snippets.cpp
|
||||
error.cpp
|
||||
flat_buffer.cpp
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
//
|
||||
// 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 <examples/doc_core_samples.hpp>
|
||||
|
||||
#include <beast/core/flat_buffer.hpp>
|
||||
#include <beast/core/ostream.hpp>
|
||||
#include <beast/test/pipe_stream.hpp>
|
||||
#include <beast/test/yield_to.hpp>
|
||||
#include <beast/unit_test/suite.hpp>
|
||||
|
||||
namespace beast {
|
||||
namespace http {
|
||||
|
||||
class doc_core_samples_test
|
||||
: public beast::unit_test::suite
|
||||
, public beast::test::enable_yield_to
|
||||
{
|
||||
public:
|
||||
void
|
||||
testDetect()
|
||||
{
|
||||
char buf[4];
|
||||
buf[0] = 0x16;
|
||||
buf[1] = 0;
|
||||
buf[2] = 0;
|
||||
buf[3] = 0;
|
||||
BEAST_EXPECT(boost::indeterminate(is_ssl_handshake(
|
||||
boost::asio::buffer(buf, 0))));
|
||||
BEAST_EXPECT(boost::indeterminate(is_ssl_handshake(
|
||||
boost::asio::buffer(buf, 1))));
|
||||
BEAST_EXPECT(boost::indeterminate(is_ssl_handshake(
|
||||
boost::asio::buffer(buf, 2))));
|
||||
BEAST_EXPECT(boost::indeterminate(is_ssl_handshake(
|
||||
boost::asio::buffer(buf, 3))));
|
||||
BEAST_EXPECT(is_ssl_handshake(
|
||||
boost::asio::buffer(buf, 4)));
|
||||
buf[0] = 0;
|
||||
BEAST_EXPECT(! is_ssl_handshake(
|
||||
boost::asio::buffer(buf, 1)));
|
||||
}
|
||||
|
||||
void
|
||||
testRead()
|
||||
{
|
||||
{
|
||||
test::pipe p{ios_};
|
||||
ostream(p.server.buffer) <<
|
||||
"\x16***";
|
||||
error_code ec;
|
||||
flat_buffer b;
|
||||
auto const result = detect_ssl(p.server, b, ec);
|
||||
BEAST_EXPECTS(! ec, ec.message());
|
||||
BEAST_EXPECT(result);
|
||||
}
|
||||
yield_to(
|
||||
[&](yield_context yield)
|
||||
{
|
||||
test::pipe p{ios_};
|
||||
ostream(p.server.buffer) <<
|
||||
"\x16***";
|
||||
error_code ec;
|
||||
flat_buffer b;
|
||||
auto const result = async_detect_ssl(p.server, b, yield[ec]);
|
||||
BEAST_EXPECTS(! ec, ec.message());
|
||||
BEAST_EXPECT(result);
|
||||
});
|
||||
}
|
||||
|
||||
void
|
||||
run()
|
||||
{
|
||||
testDetect();
|
||||
testRead();
|
||||
}
|
||||
};
|
||||
|
||||
BEAST_DEFINE_TESTSUITE(doc_core_samples,core,beast);
|
||||
|
||||
} // http
|
||||
} // beast
|
||||
@@ -6,6 +6,7 @@
|
||||
//
|
||||
|
||||
#include <examples/doc_http_samples.hpp>
|
||||
#include <examples/file_body.hpp>
|
||||
|
||||
#include <beast/core/detail/clamp.hpp>
|
||||
#include <beast/core/detail/read_size_helper.hpp>
|
||||
@@ -257,6 +258,56 @@ public:
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
void
|
||||
doFileBody()
|
||||
{
|
||||
test::pipe c{ios_};
|
||||
|
||||
boost::filesystem::path const path = "temp.txt";
|
||||
std::string const body = "Hello, world!\n";
|
||||
{
|
||||
request<string_body> req;
|
||||
req.version = 11;
|
||||
req.method(verb::put);
|
||||
req.target("/");
|
||||
req.body = body;
|
||||
req.prepare();
|
||||
write(c.client, req);
|
||||
}
|
||||
{
|
||||
flat_buffer b;
|
||||
request_parser<empty_body> p0;
|
||||
read_header(c.server, b, p0);
|
||||
BEAST_EXPECTS(p0.get().method() == verb::put,
|
||||
p0.get().method_string());
|
||||
{
|
||||
request_parser<file_body> p{std::move(p0)};
|
||||
p.get().body = path;
|
||||
read(c.server, b, p);
|
||||
}
|
||||
}
|
||||
{
|
||||
response<file_body> res;
|
||||
res.version = 11;
|
||||
res.result(status::ok);
|
||||
res.insert(field::server, "test");
|
||||
res.body = path;
|
||||
res.prepare();
|
||||
write(c.server, res);
|
||||
}
|
||||
{
|
||||
flat_buffer b;
|
||||
response<string_body> res;
|
||||
read(c.client, b, res);
|
||||
BEAST_EXPECTS(res.body == body, body);
|
||||
}
|
||||
error_code ec;
|
||||
boost::filesystem::remove(path, ec);
|
||||
BEAST_EXPECTS(! ec, ec.message());
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
void
|
||||
run()
|
||||
{
|
||||
@@ -268,6 +319,7 @@ public:
|
||||
doCustomParser();
|
||||
doHEAD();
|
||||
doDeferredBody();
|
||||
doFileBody();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -216,7 +216,8 @@ boost::asio::ip::tcp::socket sock{ios};
|
||||
|
||||
} // fxx()
|
||||
|
||||
#if 0
|
||||
// workaround for https://github.com/chriskohlhoff/asio/issues/112
|
||||
#ifdef _MSC_VER
|
||||
//[ws_snippet_21
|
||||
void echo(stream<boost::asio::ip::tcp::socket>& ws,
|
||||
multi_buffer& buffer, boost::asio::yield_context yield)
|
||||
|
||||
Reference in new issue
Block a user