forked from boostorg/beast
Boost prep
This commit is contained in:
@@ -1,6 +1,13 @@
|
||||
# Part of Beast
|
||||
#
|
||||
# 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)
|
||||
#
|
||||
# Official repository: https://github.com/boostorg/beast
|
||||
#
|
||||
|
||||
GroupSources(include/beast beast)
|
||||
GroupSources(include/boost/beast beast)
|
||||
|
||||
GroupSources(example/server-framework "/")
|
||||
GroupSources(example/common "common")
|
||||
@@ -10,9 +17,10 @@ file(GLOB_RECURSE SERVER_INCLUDES
|
||||
)
|
||||
|
||||
add_executable (server-framework
|
||||
${BEAST_INCLUDES}
|
||||
${BOOST_BEAST_INCLUDES}
|
||||
${COMMON_INCLUDES}
|
||||
${SERVER_INCLUDES}
|
||||
Jamfile
|
||||
main.cpp
|
||||
)
|
||||
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
# 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)
|
||||
#
|
||||
# Official repository: https://github.com/boostorg/beast
|
||||
#
|
||||
|
||||
exe server-framework :
|
||||
main.cpp
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<img width="880" height = "80" alt = "Beast"
|
||||
src="https://raw.githubusercontent.com/vinniefalco/Beast/master/doc/images/readme.png">
|
||||
src="https://raw.githubusercontent.com/boostorg/beast/master/doc/images/readme.png">
|
||||
|
||||
# HTTP and WebSocket built on Boost.Asio in C++11
|
||||
|
||||
@@ -67,7 +67,7 @@ ports created in the example program, and the HTTP services contained by
|
||||
the HTTP ports:
|
||||
|
||||
<img width="880" height = "344" alt = "ServerFramework"
|
||||
src="https://raw.githubusercontent.com/vinniefalco/Beast/master/doc/images/server.png">
|
||||
src="https://raw.githubusercontent.com/boostorg/beast/master/doc/images/server.png">
|
||||
|
||||
## PortHandler Requirements
|
||||
```C++
|
||||
|
||||
@@ -4,18 +4,20 @@
|
||||
// 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)
|
||||
//
|
||||
// Official repository: https://github.com/boostorg/beast
|
||||
//
|
||||
|
||||
#ifndef BEAST_EXAMPLE_SERVER_FILE_SERVICE_HPP
|
||||
#define BEAST_EXAMPLE_SERVER_FILE_SERVICE_HPP
|
||||
#ifndef BOOST_BEAST_EXAMPLE_SERVER_FILE_SERVICE_HPP
|
||||
#define BOOST_BEAST_EXAMPLE_SERVER_FILE_SERVICE_HPP
|
||||
|
||||
#include "framework.hpp"
|
||||
#include "../common/mime_types.hpp"
|
||||
|
||||
#include <beast/core/string.hpp>
|
||||
#include <beast/http/empty_body.hpp>
|
||||
#include <beast/http/file_body.hpp>
|
||||
#include <beast/http/message.hpp>
|
||||
#include <beast/http/string_body.hpp>
|
||||
#include <boost/beast/core/string.hpp>
|
||||
#include <boost/beast/http/empty_body.hpp>
|
||||
#include <boost/beast/http/file_body.hpp>
|
||||
#include <boost/beast/http/message.hpp>
|
||||
#include <boost/beast/http/string_body.hpp>
|
||||
|
||||
#include <boost/filesystem/path.hpp>
|
||||
|
||||
@@ -51,7 +53,7 @@ public:
|
||||
explicit
|
||||
file_service(
|
||||
boost::filesystem::path const& root,
|
||||
beast::string_view server)
|
||||
boost::beast::string_view server)
|
||||
: root_(root)
|
||||
, server_(server)
|
||||
{
|
||||
@@ -109,7 +111,7 @@ public:
|
||||
respond(
|
||||
Stream&&,
|
||||
endpoint_type const& ep,
|
||||
beast::http::request<Body, Fields>&& req,
|
||||
boost::beast::http::request<Body, Fields>&& req,
|
||||
Send const& send) const
|
||||
{
|
||||
boost::ignore_unused(ep);
|
||||
@@ -117,7 +119,7 @@ public:
|
||||
// Determine our action based on the method
|
||||
switch(req.method())
|
||||
{
|
||||
case beast::http::verb::get:
|
||||
case boost::beast::http::verb::get:
|
||||
{
|
||||
// For GET requests we deliver the actual file
|
||||
boost::filesystem::path rel_path(req.target().to_string());
|
||||
@@ -129,10 +131,10 @@ public:
|
||||
// Calculate full path from root
|
||||
boost::filesystem::path full_path = root_ / rel_path;
|
||||
|
||||
beast::error_code ec;
|
||||
boost::beast::error_code ec;
|
||||
auto res = get(req, full_path, ec);
|
||||
|
||||
if(ec == beast::errc::no_such_file_or_directory)
|
||||
if(ec == boost::beast::errc::no_such_file_or_directory)
|
||||
{
|
||||
send(not_found(req, rel_path));
|
||||
}
|
||||
@@ -149,7 +151,7 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
case beast::http::verb::head:
|
||||
case boost::beast::http::verb::head:
|
||||
{
|
||||
// We are just going to give them the headers they
|
||||
// would otherwise get, but without the body.
|
||||
@@ -160,10 +162,10 @@ public:
|
||||
// Calculate full path from root
|
||||
boost::filesystem::path full_path = root_ / rel_path;
|
||||
|
||||
beast::error_code ec;
|
||||
boost::beast::error_code ec;
|
||||
auto res = head(req, full_path, ec);
|
||||
|
||||
if(ec == beast::errc::no_such_file_or_directory)
|
||||
if(ec == boost::beast::errc::no_such_file_or_directory)
|
||||
{
|
||||
send(not_found(req, rel_path));
|
||||
}
|
||||
@@ -194,17 +196,17 @@ private:
|
||||
// Return an HTTP Not Found response
|
||||
//
|
||||
template<class Body, class Fields>
|
||||
beast::http::response<beast::http::string_body>
|
||||
boost::beast::http::response<boost::beast::http::string_body>
|
||||
not_found(
|
||||
beast::http::request<Body, Fields> const& req,
|
||||
boost::beast::http::request<Body, Fields> const& req,
|
||||
boost::filesystem::path const& rel_path) const
|
||||
{
|
||||
boost::ignore_unused(rel_path);
|
||||
beast::http::response<beast::http::string_body> res;
|
||||
boost::beast::http::response<boost::beast::http::string_body> res;
|
||||
res.version = req.version;
|
||||
res.result(beast::http::status::not_found);
|
||||
res.set(beast::http::field::server, server_);
|
||||
res.set(beast::http::field::content_type, "text/html");
|
||||
res.result(boost::beast::http::status::not_found);
|
||||
res.set(boost::beast::http::field::server, server_);
|
||||
res.set(boost::beast::http::field::content_type, "text/html");
|
||||
res.body = "The file was not found"; // VFALCO append rel_path
|
||||
res.prepare_payload();
|
||||
return res;
|
||||
@@ -213,18 +215,18 @@ private:
|
||||
// Return an HTTP Server Error
|
||||
//
|
||||
template<class Body, class Fields>
|
||||
beast::http::response<beast::http::string_body>
|
||||
boost::beast::http::response<boost::beast::http::string_body>
|
||||
server_error(
|
||||
beast::http::request<Body, Fields> const& req,
|
||||
boost::beast::http::request<Body, Fields> const& req,
|
||||
boost::filesystem::path const& rel_path,
|
||||
error_code const& ec) const
|
||||
{
|
||||
boost::ignore_unused(rel_path);
|
||||
beast::http::response<beast::http::string_body> res;
|
||||
boost::beast::http::response<boost::beast::http::string_body> res;
|
||||
res.version = req.version;
|
||||
res.result(beast::http::status::internal_server_error);
|
||||
res.set(beast::http::field::server, server_);
|
||||
res.set(beast::http::field::content_type, "text/html");
|
||||
res.result(boost::beast::http::status::internal_server_error);
|
||||
res.set(boost::beast::http::field::server, server_);
|
||||
res.set(boost::beast::http::field::content_type, "text/html");
|
||||
res.body = "Error: " + ec.message();
|
||||
res.prepare_payload();
|
||||
return res;
|
||||
@@ -233,43 +235,43 @@ private:
|
||||
// Return a file response to an HTTP GET request
|
||||
//
|
||||
template<class Body, class Fields>
|
||||
boost::optional<beast::http::response<beast::http::file_body>>
|
||||
boost::optional<boost::beast::http::response<boost::beast::http::file_body>>
|
||||
get(
|
||||
beast::http::request<Body, Fields> const& req,
|
||||
boost::beast::http::request<Body, Fields> const& req,
|
||||
boost::filesystem::path const& full_path,
|
||||
beast::error_code& ec) const
|
||||
boost::beast::error_code& ec) const
|
||||
{
|
||||
beast::http::response<beast::http::file_body> res;
|
||||
boost::beast::http::response<boost::beast::http::file_body> res;
|
||||
res.version = req.version;
|
||||
res.set(beast::http::field::server, server_);
|
||||
res.set(beast::http::field::content_type, mime_type(full_path));
|
||||
res.body.open(full_path.string<std::string>().c_str(), beast::file_mode::scan, ec);
|
||||
res.set(boost::beast::http::field::server, server_);
|
||||
res.set(boost::beast::http::field::content_type, mime_type(full_path));
|
||||
res.body.open(full_path.string<std::string>().c_str(), boost::beast::file_mode::scan, ec);
|
||||
if(ec)
|
||||
return boost::none;
|
||||
res.set(beast::http::field::content_length, res.body.size());
|
||||
res.set(boost::beast::http::field::content_length, res.body.size());
|
||||
return {std::move(res)};
|
||||
}
|
||||
|
||||
// Return a response to an HTTP HEAD request
|
||||
//
|
||||
template<class Body, class Fields>
|
||||
boost::optional<beast::http::response<beast::http::empty_body>>
|
||||
boost::optional<boost::beast::http::response<boost::beast::http::empty_body>>
|
||||
head(
|
||||
beast::http::request<Body, Fields> const& req,
|
||||
boost::beast::http::request<Body, Fields> const& req,
|
||||
boost::filesystem::path const& full_path,
|
||||
beast::error_code& ec) const
|
||||
boost::beast::error_code& ec) const
|
||||
{
|
||||
beast::http::response<beast::http::empty_body> res;
|
||||
boost::beast::http::response<boost::beast::http::empty_body> res;
|
||||
res.version = req.version;
|
||||
res.set(beast::http::field::server, server_);
|
||||
res.set(beast::http::field::content_type, mime_type(full_path));
|
||||
res.set(boost::beast::http::field::server, server_);
|
||||
res.set(boost::beast::http::field::content_type, mime_type(full_path));
|
||||
|
||||
// Use a manual file body here
|
||||
beast::http::file_body::value_type body;
|
||||
body.open(full_path.string<std::string>().c_str(), beast::file_mode::scan, ec);
|
||||
boost::beast::http::file_body::value_type body;
|
||||
body.open(full_path.string<std::string>().c_str(), boost::beast::file_mode::scan, ec);
|
||||
if(ec)
|
||||
return boost::none;
|
||||
res.set(beast::http::field::content_length, body.size());
|
||||
res.set(boost::beast::http::field::content_length, body.size());
|
||||
return {std::move(res)};
|
||||
}
|
||||
};
|
||||
|
||||
@@ -4,9 +4,11 @@
|
||||
// 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)
|
||||
//
|
||||
// Official repository: https://github.com/boostorg/beast
|
||||
//
|
||||
|
||||
#ifndef BEAST_EXAMPLE_SERVER_FRAMEWORK_HPP
|
||||
#define BEAST_EXAMPLE_SERVER_FRAMEWORK_HPP
|
||||
#ifndef BOOST_BEAST_EXAMPLE_SERVER_FRAMEWORK_HPP
|
||||
#define BOOST_BEAST_EXAMPLE_SERVER_FRAMEWORK_HPP
|
||||
|
||||
#include <boost/asio/io_service.hpp>
|
||||
#include <boost/asio/strand.hpp>
|
||||
|
||||
@@ -4,9 +4,11 @@
|
||||
// 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)
|
||||
//
|
||||
// Official repository: https://github.com/boostorg/beast
|
||||
//
|
||||
|
||||
#ifndef BEAST_EXAMPLE_SERVER_HTTP_ASYNC_PORT_HPP
|
||||
#define BEAST_EXAMPLE_SERVER_HTTP_ASYNC_PORT_HPP
|
||||
#ifndef BOOST_BEAST_EXAMPLE_SERVER_HTTP_ASYNC_PORT_HPP
|
||||
#define BOOST_BEAST_EXAMPLE_SERVER_HTTP_ASYNC_PORT_HPP
|
||||
|
||||
#include "server.hpp"
|
||||
|
||||
@@ -16,12 +18,12 @@
|
||||
#include "../common/rfc7231.hpp"
|
||||
#include "../common/write_msg.hpp"
|
||||
|
||||
#include <beast/core/flat_buffer.hpp>
|
||||
#include <beast/http/dynamic_body.hpp>
|
||||
#include <beast/http/parser.hpp>
|
||||
#include <beast/http/read.hpp>
|
||||
#include <beast/http/string_body.hpp>
|
||||
#include <beast/http/write.hpp>
|
||||
#include <boost/beast/core/flat_buffer.hpp>
|
||||
#include <boost/beast/http/dynamic_body.hpp>
|
||||
#include <boost/beast/http/parser.hpp>
|
||||
#include <boost/beast/http/read.hpp>
|
||||
#include <boost/beast/http/string_body.hpp>
|
||||
#include <boost/beast/http/write.hpp>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <ostream>
|
||||
@@ -57,7 +59,7 @@ class queued_http_write_impl : public queued_http_write
|
||||
Stream& stream_;
|
||||
|
||||
// The message to send, which we acquire by move or copy
|
||||
beast::http::message<isRequest, Body, Fields> msg_;
|
||||
boost::beast::http::message<isRequest, Body, Fields> msg_;
|
||||
|
||||
// The handler to invoke when the send completes.
|
||||
Handler handler_;
|
||||
@@ -70,7 +72,7 @@ public:
|
||||
template<class DeducedHandler>
|
||||
queued_http_write_impl(
|
||||
Stream& stream,
|
||||
beast::http::message<isRequest, Body, Fields>&& msg,
|
||||
boost::beast::http::message<isRequest, Body, Fields>&& msg,
|
||||
DeducedHandler&& handler)
|
||||
: stream_(stream)
|
||||
, msg_(std::move(msg))
|
||||
@@ -105,7 +107,7 @@ template<
|
||||
std::unique_ptr<queued_http_write>
|
||||
make_queued_http_write(
|
||||
Stream& stream,
|
||||
beast::http::message<isRequest, Body, Fields>&& msg,
|
||||
boost::beast::http::message<isRequest, Body, Fields>&& msg,
|
||||
Handler&& handler)
|
||||
{
|
||||
return std::unique_ptr<queued_http_write>{
|
||||
@@ -158,10 +160,10 @@ protected:
|
||||
endpoint_type ep_;
|
||||
|
||||
// The buffer for performing reads
|
||||
beast::flat_buffer buffer_;
|
||||
boost::beast::flat_buffer buffer_;
|
||||
|
||||
// The parser for reading the requests
|
||||
boost::optional<beast::http::request_parser<beast::http::dynamic_body>> parser_;
|
||||
boost::optional<boost::beast::http::request_parser<boost::beast::http::dynamic_body>> parser_;
|
||||
|
||||
// This is the queue of outgoing messages
|
||||
std::vector<std::unique_ptr<queued_http_write>> queue_;
|
||||
@@ -177,7 +179,7 @@ protected:
|
||||
public:
|
||||
// Constructor
|
||||
async_http_con_base(
|
||||
beast::string_view server_name,
|
||||
boost::beast::string_view server_name,
|
||||
std::ostream& log,
|
||||
service_list<Services...> const& services,
|
||||
std::size_t id,
|
||||
@@ -267,7 +269,7 @@ protected:
|
||||
parser_.emplace(std::piecewise_construct, std::make_tuple(1024 * 1024));
|
||||
|
||||
// Read just the header
|
||||
beast::http::async_read_header(
|
||||
boost::beast::http::async_read_header(
|
||||
impl().stream(),
|
||||
buffer_,
|
||||
*parser_,
|
||||
@@ -299,7 +301,7 @@ protected:
|
||||
// sends a message
|
||||
template<class Body, class Fields>
|
||||
void
|
||||
operator()(beast::http::response<Body, Fields>&& res) const
|
||||
operator()(boost::beast::http::response<Body, Fields>&& res) const
|
||||
{
|
||||
self_.do_write(std::move(res));
|
||||
}
|
||||
@@ -311,7 +313,7 @@ protected:
|
||||
{
|
||||
// This happens when the other end closes gracefully
|
||||
//
|
||||
if(ec == beast::http::error::end_of_stream)
|
||||
if(ec == boost::beast::http::error::end_of_stream)
|
||||
{
|
||||
// VFALCO what about the write queue?
|
||||
return impl().do_shutdown();
|
||||
@@ -342,7 +344,7 @@ protected:
|
||||
|
||||
// Read the rest of the message, if any.
|
||||
//
|
||||
beast::http::async_read(
|
||||
boost::beast::http::async_read(
|
||||
impl().stream(),
|
||||
buffer_,
|
||||
*parser_,
|
||||
@@ -413,7 +415,7 @@ protected:
|
||||
//
|
||||
template<class Body, class Fields>
|
||||
void
|
||||
do_write(beast::http::response<Body, Fields>&& res)
|
||||
do_write(boost::beast::http::response<Body, Fields>&& res)
|
||||
{
|
||||
// See if a write is in progress
|
||||
if(! writing_)
|
||||
@@ -459,7 +461,7 @@ protected:
|
||||
// should be closed afterwards. For example if
|
||||
// we send a Connection: close.
|
||||
//
|
||||
if(ec == beast::http::error::end_of_stream)
|
||||
if(ec == boost::beast::http::error::end_of_stream)
|
||||
return impl().do_shutdown();
|
||||
|
||||
// On failure just log and return
|
||||
@@ -565,7 +567,7 @@ private:
|
||||
// not_connected happens under normal
|
||||
// circumstances so don't bother reporting it.
|
||||
//
|
||||
if(ec && ec != beast::errc::not_connected)
|
||||
if(ec && ec != boost::beast::errc::not_connected)
|
||||
return this->fail("shutdown", ec);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -4,14 +4,16 @@
|
||||
// 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)
|
||||
//
|
||||
// Official repository: https://github.com/boostorg/beast
|
||||
//
|
||||
|
||||
#ifndef BEAST_EXAMPLE_SERVER_HTTP_BASE_HPP
|
||||
#define BEAST_EXAMPLE_SERVER_HTTP_BASE_HPP
|
||||
#ifndef BOOST_BEAST_EXAMPLE_SERVER_HTTP_BASE_HPP
|
||||
#define BOOST_BEAST_EXAMPLE_SERVER_HTTP_BASE_HPP
|
||||
|
||||
#include <beast/core/string.hpp>
|
||||
#include <beast/http/empty_body.hpp>
|
||||
#include <beast/http/message.hpp>
|
||||
#include <beast/http/string_body.hpp>
|
||||
#include <boost/beast/core/string.hpp>
|
||||
#include <boost/beast/http/empty_body.hpp>
|
||||
#include <boost/beast/http/message.hpp>
|
||||
#include <boost/beast/http/string_body.hpp>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <ostream>
|
||||
@@ -25,11 +27,11 @@ namespace framework {
|
||||
*/
|
||||
class http_base
|
||||
{
|
||||
beast::string_view server_name_;
|
||||
boost::beast::string_view server_name_;
|
||||
|
||||
public:
|
||||
explicit
|
||||
http_base(beast::string_view server_name)
|
||||
http_base(boost::beast::string_view server_name)
|
||||
: server_name_(server_name)
|
||||
{
|
||||
}
|
||||
@@ -38,17 +40,17 @@ protected:
|
||||
// Returns a bad request result response
|
||||
//
|
||||
template<class Body, class Fields>
|
||||
beast::http::response<beast::http::string_body>
|
||||
bad_request(beast::http::request<Body, Fields> const& req) const
|
||||
boost::beast::http::response<boost::beast::http::string_body>
|
||||
bad_request(boost::beast::http::request<Body, Fields> const& req) const
|
||||
{
|
||||
beast::http::response<beast::http::string_body> res;
|
||||
boost::beast::http::response<boost::beast::http::string_body> res;
|
||||
|
||||
// Match the version to the request
|
||||
res.version = req.version;
|
||||
|
||||
res.result(beast::http::status::bad_request);
|
||||
res.set(beast::http::field::server, server_name_);
|
||||
res.set(beast::http::field::content_type, "text/html");
|
||||
res.result(boost::beast::http::status::bad_request);
|
||||
res.set(boost::beast::http::field::server, server_name_);
|
||||
res.set(boost::beast::http::field::content_type, "text/html");
|
||||
res.body = "Bad request";
|
||||
res.prepare_payload();
|
||||
return res;
|
||||
@@ -57,16 +59,16 @@ protected:
|
||||
// Returns a 100 Continue result response
|
||||
//
|
||||
template<class Body, class Fields>
|
||||
beast::http::response<beast::http::empty_body>
|
||||
continue_100(beast::http::request<Body, Fields> const& req) const
|
||||
boost::beast::http::response<boost::beast::http::empty_body>
|
||||
continue_100(boost::beast::http::request<Body, Fields> const& req) const
|
||||
{
|
||||
beast::http::response<beast::http::empty_body> res;
|
||||
boost::beast::http::response<boost::beast::http::empty_body> res;
|
||||
|
||||
// Match the version to the request
|
||||
res.version = req.version;
|
||||
|
||||
res.result(beast::http::status::continue_);
|
||||
res.set(beast::http::field::server, server_name_);
|
||||
res.result(boost::beast::http::status::continue_);
|
||||
res.set(boost::beast::http::field::server, server_name_);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -4,9 +4,11 @@
|
||||
// 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)
|
||||
//
|
||||
// Official repository: https://github.com/boostorg/beast
|
||||
//
|
||||
|
||||
#ifndef BEAST_EXAMPLE_SERVER_HTTP_SYNC_PORT_HPP
|
||||
#define BEAST_EXAMPLE_SERVER_HTTP_SYNC_PORT_HPP
|
||||
#ifndef BOOST_BEAST_EXAMPLE_SERVER_HTTP_SYNC_PORT_HPP
|
||||
#define BOOST_BEAST_EXAMPLE_SERVER_HTTP_SYNC_PORT_HPP
|
||||
|
||||
#include "server.hpp"
|
||||
|
||||
@@ -16,13 +18,13 @@
|
||||
#include "../common/rfc7231.hpp"
|
||||
#include "../common/write_msg.hpp"
|
||||
|
||||
#include <beast/core/flat_buffer.hpp>
|
||||
#include <beast/core/handler_ptr.hpp>
|
||||
#include <beast/http/dynamic_body.hpp>
|
||||
#include <beast/http/parser.hpp>
|
||||
#include <beast/http/read.hpp>
|
||||
#include <beast/http/string_body.hpp>
|
||||
#include <beast/http/write.hpp>
|
||||
#include <boost/beast/core/flat_buffer.hpp>
|
||||
#include <boost/beast/core/handler_ptr.hpp>
|
||||
#include <boost/beast/http/dynamic_body.hpp>
|
||||
#include <boost/beast/http/parser.hpp>
|
||||
#include <boost/beast/http/read.hpp>
|
||||
#include <boost/beast/http/string_body.hpp>
|
||||
#include <boost/beast/http/write.hpp>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <ostream>
|
||||
@@ -68,12 +70,12 @@ class sync_http_con_base
|
||||
endpoint_type ep_;
|
||||
|
||||
// The buffer for performing reads
|
||||
beast::flat_buffer buffer_;
|
||||
boost::beast::flat_buffer buffer_;
|
||||
|
||||
public:
|
||||
/// Constructor
|
||||
sync_http_con_base(
|
||||
beast::string_view server_name,
|
||||
boost::beast::string_view server_name,
|
||||
std::ostream& log,
|
||||
service_list<Services...> const& services,
|
||||
std::size_t id,
|
||||
@@ -155,10 +157,10 @@ private:
|
||||
template<class Body, class Fields>
|
||||
void
|
||||
operator()(
|
||||
beast::http::response<Body, Fields>&& res) const
|
||||
boost::beast::http::response<Body, Fields>&& res) const
|
||||
{
|
||||
beast::http::serializer<false, Body, Fields> sr{res};
|
||||
beast::http::write(self_.impl().stream(), sr, ec_);
|
||||
boost::beast::http::serializer<false, Body, Fields> sr{res};
|
||||
boost::beast::http::write(self_.impl().stream(), sr, ec_);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -189,19 +191,19 @@ private:
|
||||
// We construct the dynamic body with a 1MB limit
|
||||
// to prevent vulnerability to buffer attacks.
|
||||
//
|
||||
beast::http::request_parser<beast::http::dynamic_body> parser(
|
||||
boost::beast::http::request_parser<boost::beast::http::dynamic_body> parser(
|
||||
std::piecewise_construct, std::make_tuple(1024* 1024));
|
||||
|
||||
// Read the header first
|
||||
beast::http::read_header(impl().stream(), buffer_, parser, ec);
|
||||
boost::beast::http::read_header(impl().stream(), buffer_, parser, ec);
|
||||
|
||||
// This happens when the other end closes gracefully
|
||||
//
|
||||
if(ec == beast::http::error::end_of_stream)
|
||||
if(ec == boost::beast::http::error::end_of_stream)
|
||||
{
|
||||
// Give the derived class a chance to do stuff
|
||||
impl().do_shutdown(ec);
|
||||
if(ec && ec != beast::errc::not_connected)
|
||||
if(ec && ec != boost::beast::errc::not_connected)
|
||||
return fail("shutdown", ec);
|
||||
return;
|
||||
}
|
||||
@@ -228,11 +230,11 @@ private:
|
||||
// should be closed afterwards. For example if
|
||||
// we send a Connection: close.
|
||||
//
|
||||
if(ec == beast::http::error::end_of_stream)
|
||||
if(ec == boost::beast::http::error::end_of_stream)
|
||||
{
|
||||
// Give the derived class a chance to do stuff
|
||||
impl().do_shutdown(ec);
|
||||
if(ec && ec != beast::errc::not_connected)
|
||||
if(ec && ec != boost::beast::errc::not_connected)
|
||||
return fail("shutdown", ec);
|
||||
return;
|
||||
}
|
||||
@@ -245,7 +247,7 @@ private:
|
||||
|
||||
// Read the rest of the message, if any.
|
||||
//
|
||||
beast::http::read(impl().stream(), buffer_, parser, ec);
|
||||
boost::beast::http::read(impl().stream(), buffer_, parser, ec);
|
||||
|
||||
// Shouldn't be getting end_of_stream here;
|
||||
// that would mean that we got an incomplete
|
||||
@@ -272,11 +274,11 @@ private:
|
||||
// should be closed afterwards. For example if
|
||||
// we send a Connection: close.
|
||||
//
|
||||
if(ec == beast::http::error::end_of_stream)
|
||||
if(ec == boost::beast::http::error::end_of_stream)
|
||||
{
|
||||
// Give the derived class a chance to do stuff
|
||||
impl().do_shutdown(ec);
|
||||
if(ec && ec != beast::errc::not_connected)
|
||||
if(ec && ec != boost::beast::errc::not_connected)
|
||||
return fail("shutdown", ec);
|
||||
return;
|
||||
}
|
||||
@@ -293,10 +295,10 @@ private:
|
||||
// should be closed afterwards. For example if
|
||||
// we send a Connection: close.
|
||||
//
|
||||
if(ec == beast::http::error::end_of_stream)
|
||||
if(ec == boost::beast::http::error::end_of_stream)
|
||||
{
|
||||
// Give the derived class a chance to do stuff
|
||||
if(ec && ec != beast::errc::not_connected)
|
||||
if(ec && ec != boost::beast::errc::not_connected)
|
||||
return fail("shutdown", ec);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -4,9 +4,11 @@
|
||||
// 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)
|
||||
//
|
||||
// Official repository: https://github.com/boostorg/beast
|
||||
//
|
||||
|
||||
#ifndef BEAST_EXAMPLE_SERVER_HTTPS_PORTS_HPP
|
||||
#define BEAST_EXAMPLE_SERVER_HTTPS_PORTS_HPP
|
||||
#ifndef BOOST_BEAST_EXAMPLE_SERVER_HTTPS_PORTS_HPP
|
||||
#define BOOST_BEAST_EXAMPLE_SERVER_HTTPS_PORTS_HPP
|
||||
|
||||
#include "http_sync_port.hpp"
|
||||
#include "http_async_port.hpp"
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
// 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)
|
||||
//
|
||||
// Official repository: https://github.com/boostorg/beast
|
||||
//
|
||||
|
||||
#include "server.hpp"
|
||||
|
||||
@@ -12,7 +14,7 @@
|
||||
#include "ws_async_port.hpp"
|
||||
#include "ws_sync_port.hpp"
|
||||
|
||||
#if BEAST_USE_OPENSSL
|
||||
#if BOOST_BEAST_USE_OPENSSL
|
||||
#include "https_ports.hpp"
|
||||
#include "multi_port.hpp"
|
||||
#include "wss_ports.hpp"
|
||||
@@ -58,17 +60,17 @@ sig_wait()
|
||||
*/
|
||||
class set_ws_options
|
||||
{
|
||||
beast::websocket::permessage_deflate pmd_;
|
||||
boost::beast::websocket::permessage_deflate pmd_;
|
||||
|
||||
public:
|
||||
set_ws_options(beast::websocket::permessage_deflate const& pmd)
|
||||
set_ws_options(boost::beast::websocket::permessage_deflate const& pmd)
|
||||
: pmd_(pmd)
|
||||
{
|
||||
}
|
||||
|
||||
template<class NextLayer>
|
||||
void
|
||||
operator()(beast::websocket::stream<NextLayer>& ws) const
|
||||
operator()(boost::beast::websocket::stream<NextLayer>& ws) const
|
||||
{
|
||||
ws.auto_fragment(false);
|
||||
ws.set_option(pmd_);
|
||||
@@ -82,7 +84,7 @@ main(
|
||||
char const* av[])
|
||||
{
|
||||
using namespace framework;
|
||||
using namespace beast::http;
|
||||
using namespace boost::beast::http;
|
||||
|
||||
// Helper for reporting failures
|
||||
//
|
||||
@@ -131,7 +133,7 @@ main(
|
||||
boost::filesystem::path const root = vm["root"].as<std::string>();
|
||||
|
||||
// These settings will be applied to all new websocket connections
|
||||
beast::websocket::permessage_deflate pmd;
|
||||
boost::beast::websocket::permessage_deflate pmd;
|
||||
pmd.client_enable = true;
|
||||
pmd.server_enable = true;
|
||||
pmd.compLevel = 3;
|
||||
@@ -263,7 +265,7 @@ main(
|
||||
// an installed and configured OpenSSL as part of the build.
|
||||
//
|
||||
|
||||
#if BEAST_USE_OPENSSL
|
||||
#if BOOST_BEAST_USE_OPENSSL
|
||||
|
||||
ssl_certificate cert;
|
||||
|
||||
|
||||
@@ -4,9 +4,11 @@
|
||||
// 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)
|
||||
//
|
||||
// Official repository: https://github.com/boostorg/beast
|
||||
//
|
||||
|
||||
#ifndef BEAST_EXAMPLE_SERVER_MULTI_PORT_HPP
|
||||
#define BEAST_EXAMPLE_SERVER_MULTI_PORT_HPP
|
||||
#ifndef BOOST_BEAST_EXAMPLE_SERVER_MULTI_PORT_HPP
|
||||
#define BOOST_BEAST_EXAMPLE_SERVER_MULTI_PORT_HPP
|
||||
|
||||
#include "ws_async_port.hpp"
|
||||
#include "http_async_port.hpp"
|
||||
@@ -15,7 +17,7 @@
|
||||
|
||||
#include "../common/detect_ssl.hpp"
|
||||
|
||||
#include <beast/core.hpp>
|
||||
#include <boost/beast/core.hpp>
|
||||
|
||||
#include <boost/function.hpp>
|
||||
|
||||
@@ -54,7 +56,7 @@ class multi_con
|
||||
boost::asio::ssl::context& ctx_;
|
||||
|
||||
// Holds the data we read during ssl detection
|
||||
beast::flat_static_buffer<6> buffer_;
|
||||
boost::beast::flat_static_buffer<6> buffer_;
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
@@ -181,7 +183,7 @@ private:
|
||||
// not_connected happens under normal
|
||||
// circumstances so don't bother reporting it.
|
||||
//
|
||||
if(ec && ec != beast::errc::not_connected)
|
||||
if(ec && ec != boost::beast::errc::not_connected)
|
||||
return this->fail("shutdown", ec);
|
||||
}
|
||||
};
|
||||
@@ -213,8 +215,8 @@ protected:
|
||||
// crash with gcc and clang using libstdc++
|
||||
|
||||
// The types of the on_stream callback
|
||||
using on_new_stream_cb1 = boost::function<void(beast::websocket::stream<socket_type>&)>;
|
||||
using on_new_stream_cb2 = boost::function<void(beast::websocket::stream<ssl_stream<socket_type>>&)>;
|
||||
using on_new_stream_cb1 = boost::function<void(boost::beast::websocket::stream<socket_type>&)>;
|
||||
using on_new_stream_cb2 = boost::function<void(boost::beast::websocket::stream<ssl_stream<socket_type>>&)>;
|
||||
|
||||
// Reference to the server instance that made us
|
||||
server& instance_;
|
||||
@@ -244,7 +246,7 @@ public:
|
||||
should have this equivalent signature:
|
||||
@code
|
||||
template<class NextLayer>
|
||||
void callback(beast::websocket::stream<NextLayer>&);
|
||||
void callback(boost::beast::websocket::stream<NextLayer>&);
|
||||
@endcode
|
||||
In C++14 this can be accomplished with a generic lambda. In
|
||||
C++11 it will be necessary to write out a lambda manually,
|
||||
@@ -280,7 +282,7 @@ public:
|
||||
on_upgrade(
|
||||
socket_type&& sock,
|
||||
endpoint_type ep,
|
||||
beast::http::request<Body>&& req)
|
||||
boost::beast::http::request<Body>&& req)
|
||||
{
|
||||
// Create the connection and call the version of
|
||||
// run that takes the request since we have it already
|
||||
@@ -311,7 +313,7 @@ public:
|
||||
on_upgrade(
|
||||
ssl_stream<socket_type>&& stream,
|
||||
endpoint_type ep,
|
||||
beast::http::request<Body>&& req)
|
||||
boost::beast::http::request<Body>&& req)
|
||||
{
|
||||
std::make_shared<async_wss_con>(
|
||||
std::move(stream),
|
||||
|
||||
@@ -4,9 +4,11 @@
|
||||
// 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)
|
||||
//
|
||||
// Official repository: https://github.com/boostorg/beast
|
||||
//
|
||||
|
||||
#ifndef BEAST_EXAMPLE_FRAMEWORK_SERVER_HPP
|
||||
#define BEAST_EXAMPLE_FRAMEWORK_SERVER_HPP
|
||||
#ifndef BOOST_BEAST_EXAMPLE_FRAMEWORK_SERVER_HPP
|
||||
#define BOOST_BEAST_EXAMPLE_FRAMEWORK_SERVER_HPP
|
||||
|
||||
#include "framework.hpp"
|
||||
|
||||
|
||||
@@ -4,13 +4,15 @@
|
||||
// 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)
|
||||
//
|
||||
// Official repository: https://github.com/boostorg/beast
|
||||
//
|
||||
|
||||
#ifndef BEAST_EXAMPLE_SERVER_SERVICE_LIST_HPP
|
||||
#define BEAST_EXAMPLE_SERVER_SERVICE_LIST_HPP
|
||||
#ifndef BOOST_BEAST_EXAMPLE_SERVER_SERVICE_LIST_HPP
|
||||
#define BOOST_BEAST_EXAMPLE_SERVER_SERVICE_LIST_HPP
|
||||
|
||||
#include "framework.hpp"
|
||||
|
||||
#include <beast/http/message.hpp>
|
||||
#include <boost/beast/http/message.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
#include <utility>
|
||||
|
||||
@@ -118,7 +120,7 @@ public:
|
||||
respond(
|
||||
Stream&& stream,
|
||||
endpoint_type const& ep,
|
||||
beast::http::request<Body>&& req,
|
||||
boost::beast::http::request<Body>&& req,
|
||||
Send const& send) const
|
||||
{
|
||||
return try_respond(
|
||||
@@ -141,7 +143,7 @@ private:
|
||||
try_respond(
|
||||
Stream&&,
|
||||
endpoint_type const&,
|
||||
beast::http::request<Body>&&,
|
||||
boost::beast::http::request<Body>&&,
|
||||
Send const&,
|
||||
C<sizeof...(Services)> const&) const
|
||||
{
|
||||
@@ -162,7 +164,7 @@ private:
|
||||
try_respond(
|
||||
Stream&& stream,
|
||||
endpoint_type const& ep,
|
||||
beast::http::request<Body>&& req,
|
||||
boost::beast::http::request<Body>&& req,
|
||||
Send const& send,
|
||||
C<I> const&) const
|
||||
{
|
||||
|
||||
@@ -4,9 +4,11 @@
|
||||
// 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)
|
||||
//
|
||||
// Official repository: https://github.com/boostorg/beast
|
||||
//
|
||||
|
||||
#ifndef BEAST_EXAMPLE_SERVER_SSL_CERTIFICATE_HPP
|
||||
#define BEAST_EXAMPLE_SERVER_SSL_CERTIFICATE_HPP
|
||||
#ifndef BOOST_BEAST_EXAMPLE_SERVER_SSL_CERTIFICATE_HPP
|
||||
#define BOOST_BEAST_EXAMPLE_SERVER_SSL_CERTIFICATE_HPP
|
||||
|
||||
#include <boost/asio/buffer.hpp>
|
||||
#include <boost/asio/ssl/context.hpp>
|
||||
|
||||
@@ -4,14 +4,16 @@
|
||||
// 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)
|
||||
//
|
||||
// Official repository: https://github.com/boostorg/beast
|
||||
//
|
||||
|
||||
#ifndef BEAST_EXAMPLE_SERVER_WS_ASYNC_PORT_HPP
|
||||
#define BEAST_EXAMPLE_SERVER_WS_ASYNC_PORT_HPP
|
||||
#ifndef BOOST_BEAST_EXAMPLE_SERVER_WS_ASYNC_PORT_HPP
|
||||
#define BOOST_BEAST_EXAMPLE_SERVER_WS_ASYNC_PORT_HPP
|
||||
|
||||
#include "server.hpp"
|
||||
|
||||
#include <beast/core/multi_buffer.hpp>
|
||||
#include <beast/websocket/stream.hpp>
|
||||
#include <boost/beast/core/multi_buffer.hpp>
|
||||
#include <boost/beast/websocket/stream.hpp>
|
||||
#include <boost/function.hpp>
|
||||
#include <memory>
|
||||
#include <ostream>
|
||||
@@ -47,7 +49,7 @@ class async_ws_con_base
|
||||
endpoint_type ep_;
|
||||
|
||||
// This is used to hold the message data
|
||||
beast::multi_buffer buffer_;
|
||||
boost::beast::multi_buffer buffer_;
|
||||
|
||||
protected:
|
||||
// The strand makes sure that our data is
|
||||
@@ -59,7 +61,7 @@ public:
|
||||
// Constructor
|
||||
template<class Callback>
|
||||
async_ws_con_base(
|
||||
beast::string_view server_name,
|
||||
boost::beast::string_view server_name,
|
||||
std::ostream& log,
|
||||
std::size_t id,
|
||||
endpoint_type const& ep,
|
||||
@@ -92,16 +94,16 @@ public:
|
||||
//
|
||||
template<class Body>
|
||||
void
|
||||
run(beast::http::request<Body> const& req)
|
||||
run(boost::beast::http::request<Body> const& req)
|
||||
{
|
||||
// Call the overload of accept() which takes
|
||||
// the request by parameter, instead of reading
|
||||
// it from the network.
|
||||
//
|
||||
impl().stream().async_accept_ex(req,
|
||||
[&](beast::websocket::response_type& res)
|
||||
[&](boost::beast::websocket::response_type& res)
|
||||
{
|
||||
res.set(beast::http::field::server, server_name_);
|
||||
res.set(boost::beast::http::field::server, server_name_);
|
||||
},
|
||||
strand_.wrap(std::bind(
|
||||
&async_ws_con_base::on_accept,
|
||||
@@ -118,9 +120,9 @@ protected:
|
||||
// to send back the response.
|
||||
//
|
||||
impl().stream().async_accept_ex(
|
||||
[&](beast::websocket::response_type& res)
|
||||
[&](boost::beast::websocket::response_type& res)
|
||||
{
|
||||
res.set(beast::http::field::server, server_name_);
|
||||
res.set(boost::beast::http::field::server, server_name_);
|
||||
},
|
||||
strand_.wrap(std::bind(
|
||||
&async_ws_con_base::on_accept,
|
||||
@@ -133,7 +135,7 @@ protected:
|
||||
void
|
||||
fail(std::string what, error_code ec)
|
||||
{
|
||||
if(ec != beast::websocket::error::closed)
|
||||
if(ec != boost::beast::websocket::error::closed)
|
||||
log_ <<
|
||||
"[#" << id_ << " " << ep_ << "] " <<
|
||||
what << ": " << ec.message() << std::endl;
|
||||
@@ -224,7 +226,7 @@ class async_ws_con
|
||||
// The stream should be created before the base class so
|
||||
// use the "base from member" idiom.
|
||||
//
|
||||
, public base_from_member<beast::websocket::stream<socket_type>>
|
||||
, public base_from_member<boost::beast::websocket::stream<socket_type>>
|
||||
|
||||
// Constructs last, destroys first
|
||||
//
|
||||
@@ -240,7 +242,7 @@ public:
|
||||
async_ws_con(
|
||||
socket_type&& sock,
|
||||
Args&&... args)
|
||||
: base_from_member<beast::websocket::stream<socket_type>>(std::move(sock))
|
||||
: base_from_member<boost::beast::websocket::stream<socket_type>>(std::move(sock))
|
||||
, async_ws_con_base<async_ws_con>(std::forward<Args>(args)...)
|
||||
{
|
||||
}
|
||||
@@ -252,7 +254,7 @@ public:
|
||||
// class to work with different return types for `stream()` such
|
||||
// as a `boost::asio::ip::tcp::socket&` or a `boost::asio::ssl::stream&`
|
||||
//
|
||||
beast::websocket::stream<socket_type>&
|
||||
boost::beast::websocket::stream<socket_type>&
|
||||
stream()
|
||||
{
|
||||
return this->member;
|
||||
@@ -282,7 +284,7 @@ class ws_async_port
|
||||
// The type of the on_new_stream callback
|
||||
//
|
||||
using on_new_stream_cb =
|
||||
boost::function<void(beast::websocket::stream<socket_type>&)>;
|
||||
boost::function<void(boost::beast::websocket::stream<socket_type>&)>;
|
||||
|
||||
server& instance_;
|
||||
std::ostream& log_;
|
||||
@@ -301,7 +303,7 @@ public:
|
||||
should have this equivalent signature:
|
||||
@code
|
||||
template<class NextLayer>
|
||||
void callback(beast::websocket::stream<NextLayer>&);
|
||||
void callback(boost::beast::websocket::stream<NextLayer>&);
|
||||
@endcode
|
||||
In C++14 this can be accomplished with a generic lambda. In
|
||||
C++11 it will be necessary to write out a lambda manually,
|
||||
@@ -357,7 +359,7 @@ public:
|
||||
on_upgrade(
|
||||
socket_type&& sock,
|
||||
endpoint_type ep,
|
||||
beast::http::request<Body>&& req)
|
||||
boost::beast::http::request<Body>&& req)
|
||||
{
|
||||
std::make_shared<async_ws_con>(
|
||||
std::move(sock),
|
||||
|
||||
@@ -4,14 +4,16 @@
|
||||
// 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)
|
||||
//
|
||||
// Official repository: https://github.com/boostorg/beast
|
||||
//
|
||||
|
||||
#ifndef BEAST_EXAMPLE_SERVER_WS_SYNC_PORT_HPP
|
||||
#define BEAST_EXAMPLE_SERVER_WS_SYNC_PORT_HPP
|
||||
#ifndef BOOST_BEAST_EXAMPLE_SERVER_WS_SYNC_PORT_HPP
|
||||
#define BOOST_BEAST_EXAMPLE_SERVER_WS_SYNC_PORT_HPP
|
||||
|
||||
#include "server.hpp"
|
||||
|
||||
#include <beast/core/multi_buffer.hpp>
|
||||
#include <beast/websocket.hpp>
|
||||
#include <boost/beast/core/multi_buffer.hpp>
|
||||
#include <boost/beast/websocket.hpp>
|
||||
#include <boost/function.hpp>
|
||||
#include <memory>
|
||||
#include <ostream>
|
||||
@@ -60,7 +62,7 @@ public:
|
||||
//
|
||||
template<class Callback>
|
||||
sync_ws_con_base(
|
||||
beast::string_view server_name,
|
||||
boost::beast::string_view server_name,
|
||||
std::ostream& log,
|
||||
std::size_t id,
|
||||
endpoint_type const& ep,
|
||||
@@ -95,9 +97,9 @@ public:
|
||||
//
|
||||
template<class Body>
|
||||
void
|
||||
run(beast::http::request<Body>&& req)
|
||||
run(boost::beast::http::request<Body>&& req)
|
||||
{
|
||||
BOOST_ASSERT(beast::websocket::is_upgrade(req));
|
||||
BOOST_ASSERT(boost::beast::websocket::is_upgrade(req));
|
||||
|
||||
// We need to transfer ownership of the request object into
|
||||
// the lambda, but there's no C++14 lambda capture
|
||||
@@ -119,7 +121,7 @@ protected:
|
||||
// Don't report the "closed" error since that
|
||||
// happens under normal circumstances.
|
||||
//
|
||||
if(ec && ec != beast::websocket::error::closed)
|
||||
if(ec && ec != boost::beast::websocket::error::closed)
|
||||
{
|
||||
log_ <<
|
||||
"[#" << id_ << " " << ep_ << "] " <<
|
||||
@@ -148,9 +150,9 @@ private:
|
||||
// to send back the response.
|
||||
//
|
||||
impl().stream().accept_ex(
|
||||
[&](beast::websocket::response_type& res)
|
||||
[&](boost::beast::websocket::response_type& res)
|
||||
{
|
||||
res.insert(beast::http::field::server, server_name_);
|
||||
res.insert(boost::beast::http::field::server, server_name_);
|
||||
},
|
||||
ec);
|
||||
|
||||
@@ -172,7 +174,7 @@ private:
|
||||
class lambda
|
||||
{
|
||||
std::shared_ptr<sync_ws_con_base> self_;
|
||||
beast::http::request<Body> req_;
|
||||
boost::beast::http::request<Body> req_;
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
@@ -181,11 +183,11 @@ private:
|
||||
//
|
||||
lambda(
|
||||
std::shared_ptr<sync_ws_con_base> self,
|
||||
beast::http::request<Body>&& req)
|
||||
boost::beast::http::request<Body>&& req)
|
||||
: self_(std::move(self))
|
||||
, req_(std::move(req))
|
||||
{
|
||||
BOOST_ASSERT(beast::websocket::is_upgrade(req_));
|
||||
BOOST_ASSERT(boost::beast::websocket::is_upgrade(req_));
|
||||
}
|
||||
|
||||
// Invoke the lambda
|
||||
@@ -193,7 +195,7 @@ private:
|
||||
void
|
||||
operator()()
|
||||
{
|
||||
BOOST_ASSERT(beast::websocket::is_upgrade(req_));
|
||||
BOOST_ASSERT(boost::beast::websocket::is_upgrade(req_));
|
||||
error_code ec;
|
||||
{
|
||||
// Move the message to the stack so we can get
|
||||
@@ -207,9 +209,9 @@ private:
|
||||
// it from the network.
|
||||
//
|
||||
self_->impl().stream().accept_ex(req,
|
||||
[&](beast::websocket::response_type& res)
|
||||
[&](boost::beast::websocket::response_type& res)
|
||||
{
|
||||
res.insert(beast::http::field::server, self_->server_name_);
|
||||
res.insert(boost::beast::http::field::server, self_->server_name_);
|
||||
},
|
||||
ec);
|
||||
}
|
||||
@@ -233,7 +235,7 @@ private:
|
||||
// This buffer holds the message. We place a one
|
||||
// megabyte limit on the size to prevent abuse.
|
||||
//
|
||||
beast::multi_buffer buffer{1024*1024};
|
||||
boost::beast::multi_buffer buffer{1024*1024};
|
||||
|
||||
// Read the message
|
||||
//
|
||||
@@ -276,7 +278,7 @@ class sync_ws_con
|
||||
// The stream should be created before the base class so
|
||||
// use the "base from member" idiom.
|
||||
//
|
||||
, public base_from_member<beast::websocket::stream<socket_type>>
|
||||
, public base_from_member<boost::beast::websocket::stream<socket_type>>
|
||||
|
||||
// Constructs last, destroys first
|
||||
//
|
||||
@@ -290,7 +292,7 @@ public:
|
||||
sync_ws_con(
|
||||
socket_type&& sock,
|
||||
Args&&... args)
|
||||
: base_from_member<beast::websocket::stream<socket_type>>(std::move(sock))
|
||||
: base_from_member<boost::beast::websocket::stream<socket_type>>(std::move(sock))
|
||||
, sync_ws_con_base<sync_ws_con>(std::forward<Args>(args)...)
|
||||
{
|
||||
}
|
||||
@@ -302,7 +304,7 @@ public:
|
||||
// class to work with different return types for `stream()` such
|
||||
// as a `boost::asio::ip::tcp::socket&` or a `boost::asio::ssl::stream&`
|
||||
//
|
||||
beast::websocket::stream<socket_type>&
|
||||
boost::beast::websocket::stream<socket_type>&
|
||||
stream()
|
||||
{
|
||||
return this->member;
|
||||
@@ -337,7 +339,7 @@ class ws_sync_port
|
||||
// The type of the on_new_stream callback
|
||||
//
|
||||
using on_new_stream_cb =
|
||||
boost::function<void(beast::websocket::stream<socket_type>&)>;
|
||||
boost::function<void(boost::beast::websocket::stream<socket_type>&)>;
|
||||
|
||||
server& instance_;
|
||||
std::ostream& log_;
|
||||
@@ -356,7 +358,7 @@ public:
|
||||
should have this equivalent signature:
|
||||
@code
|
||||
template<class NextLayer>
|
||||
void callback(beast::websocket::stream<NextLayer>&);
|
||||
void callback(boost::beast::websocket::stream<NextLayer>&);
|
||||
@endcode
|
||||
In C++14 this can be accomplished with a generic lambda. In
|
||||
C++11 it will be necessary to write out a lambda manually,
|
||||
@@ -412,7 +414,7 @@ public:
|
||||
on_upgrade(
|
||||
socket_type&& sock,
|
||||
endpoint_type ep,
|
||||
beast::http::request<Body>&& req)
|
||||
boost::beast::http::request<Body>&& req)
|
||||
{
|
||||
// Create the connection object and run it,
|
||||
// transferring ownership of the ugprade request.
|
||||
|
||||
@@ -4,14 +4,16 @@
|
||||
// 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)
|
||||
//
|
||||
// Official repository: https://github.com/boostorg/beast
|
||||
//
|
||||
|
||||
#ifndef BEAST_EXAMPLE_SERVER_WS_UPGRADE_SERVICE_HPP
|
||||
#define BEAST_EXAMPLE_SERVER_WS_UPGRADE_SERVICE_HPP
|
||||
#ifndef BOOST_BEAST_EXAMPLE_SERVER_WS_UPGRADE_SERVICE_HPP
|
||||
#define BOOST_BEAST_EXAMPLE_SERVER_WS_UPGRADE_SERVICE_HPP
|
||||
|
||||
#include "framework.hpp"
|
||||
|
||||
#include <beast/http/message.hpp>
|
||||
#include <beast/websocket/rfc6455.hpp>
|
||||
#include <boost/beast/http/message.hpp>
|
||||
#include <boost/beast/websocket/rfc6455.hpp>
|
||||
#include <memory>
|
||||
|
||||
namespace framework {
|
||||
@@ -73,13 +75,13 @@ public:
|
||||
respond(
|
||||
Stream&& stream,
|
||||
endpoint_type const& ep,
|
||||
beast::http::request<Body>&& req,
|
||||
boost::beast::http::request<Body>&& req,
|
||||
Send const&) const
|
||||
{
|
||||
// If its not an upgrade request, return `false`
|
||||
// to indicate that we are not handling it.
|
||||
//
|
||||
if(! beast::websocket::is_upgrade(req))
|
||||
if(! boost::beast::websocket::is_upgrade(req))
|
||||
return false;
|
||||
|
||||
// Its an ugprade request, so transfer ownership
|
||||
|
||||
@@ -4,9 +4,11 @@
|
||||
// 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)
|
||||
//
|
||||
// Official repository: https://github.com/boostorg/beast
|
||||
//
|
||||
|
||||
#ifndef BEAST_EXAMPLE_SERVER_WSS_PORTS_HPP
|
||||
#define BEAST_EXAMPLE_SERVER_WSS_PORTS_HPP
|
||||
#ifndef BOOST_BEAST_EXAMPLE_SERVER_WSS_PORTS_HPP
|
||||
#define BOOST_BEAST_EXAMPLE_SERVER_WSS_PORTS_HPP
|
||||
|
||||
#include "ws_sync_port.hpp"
|
||||
#include "ws_async_port.hpp"
|
||||
@@ -36,7 +38,7 @@ class sync_wss_con
|
||||
// The stream should be created before the base class so
|
||||
// use the "base from member" idiom.
|
||||
//
|
||||
, public base_from_member<beast::websocket::stream<ssl_stream<socket_type>>>
|
||||
, public base_from_member<boost::beast::websocket::stream<ssl_stream<socket_type>>>
|
||||
|
||||
// Constructs last, destroys first
|
||||
//
|
||||
@@ -53,7 +55,7 @@ public:
|
||||
socket_type&& sock,
|
||||
boost::asio::ssl::context& ctx,
|
||||
Args&&... args)
|
||||
: base_from_member<beast::websocket::stream<ssl_stream<socket_type>>>(std::move(sock), ctx)
|
||||
: base_from_member<boost::beast::websocket::stream<ssl_stream<socket_type>>>(std::move(sock), ctx)
|
||||
, sync_ws_con_base<sync_wss_con>(std::forward<Args>(args)...)
|
||||
{
|
||||
}
|
||||
@@ -64,7 +66,7 @@ public:
|
||||
sync_wss_con(
|
||||
ssl_stream<socket_type>&& stream,
|
||||
Args&&... args)
|
||||
: base_from_member<beast::websocket::stream<ssl_stream<socket_type>>>(std::move(stream))
|
||||
: base_from_member<boost::beast::websocket::stream<ssl_stream<socket_type>>>(std::move(stream))
|
||||
, sync_ws_con_base<sync_wss_con>(std::forward<Args>(args)...)
|
||||
{
|
||||
}
|
||||
@@ -76,7 +78,7 @@ public:
|
||||
// class to work with different return types for `stream()` such
|
||||
// as a `boost::asio::ip::tcp::socket&` or a `boost::asio::ssl::stream&`
|
||||
//
|
||||
beast::websocket::stream<ssl_stream<socket_type>>&
|
||||
boost::beast::websocket::stream<ssl_stream<socket_type>>&
|
||||
stream()
|
||||
{
|
||||
return this->member;
|
||||
@@ -116,7 +118,7 @@ class async_wss_con
|
||||
// The stream should be created before the base class so
|
||||
// use the "base from member" idiom.
|
||||
//
|
||||
, public base_from_member<beast::websocket::stream<ssl_stream<socket_type>>>
|
||||
, public base_from_member<boost::beast::websocket::stream<ssl_stream<socket_type>>>
|
||||
|
||||
// Constructs last, destroys first
|
||||
//
|
||||
@@ -132,7 +134,7 @@ public:
|
||||
socket_type&& sock,
|
||||
boost::asio::ssl::context& ctx,
|
||||
Args&&... args)
|
||||
: base_from_member<beast::websocket::stream<ssl_stream<socket_type>>>(std::move(sock), ctx)
|
||||
: base_from_member<boost::beast::websocket::stream<ssl_stream<socket_type>>>(std::move(sock), ctx)
|
||||
, async_ws_con_base<async_wss_con>(std::forward<Args>(args)...)
|
||||
{
|
||||
}
|
||||
@@ -143,7 +145,7 @@ public:
|
||||
async_wss_con(
|
||||
ssl_stream<socket_type>&& stream,
|
||||
Args&&... args)
|
||||
: base_from_member<beast::websocket::stream<ssl_stream<socket_type>>>(std::move(stream))
|
||||
: base_from_member<boost::beast::websocket::stream<ssl_stream<socket_type>>>(std::move(stream))
|
||||
, async_ws_con_base<async_wss_con>(std::forward<Args>(args)...)
|
||||
{
|
||||
}
|
||||
@@ -155,7 +157,7 @@ public:
|
||||
// class to work with different return types for `stream()` such
|
||||
// as a `boost::asio::ip::tcp::socket&` or a `boost::asio::ssl::stream&`
|
||||
//
|
||||
beast::websocket::stream<ssl_stream<socket_type>>&
|
||||
boost::beast::websocket::stream<ssl_stream<socket_type>>&
|
||||
stream()
|
||||
{
|
||||
return this->member;
|
||||
@@ -211,10 +213,10 @@ class wss_sync_port
|
||||
// The types of the on_new_stream callbacks
|
||||
//
|
||||
using on_new_stream_cb1 =
|
||||
boost::function<void(beast::websocket::stream<socket_type>&)>;
|
||||
boost::function<void(boost::beast::websocket::stream<socket_type>&)>;
|
||||
|
||||
using on_new_stream_cb2 =
|
||||
boost::function<void(beast::websocket::stream<ssl_stream<socket_type>>&)>;
|
||||
boost::function<void(boost::beast::websocket::stream<ssl_stream<socket_type>>&)>;
|
||||
|
||||
server& instance_;
|
||||
std::ostream& log_;
|
||||
@@ -237,7 +239,7 @@ public:
|
||||
should have this equivalent signature:
|
||||
@code
|
||||
template<class NextLayer>
|
||||
void callback(beast::websocket::stream<NextLayer>&);
|
||||
void callback(boost::beast::websocket::stream<NextLayer>&);
|
||||
@endcode
|
||||
In C++14 this can be accomplished with a generic lambda. In
|
||||
C++11 it will be necessary to write out a lambda manually,
|
||||
@@ -297,7 +299,7 @@ public:
|
||||
on_upgrade(
|
||||
ssl_stream<socket_type>&& stream,
|
||||
endpoint_type ep,
|
||||
beast::http::request<Body>&& req)
|
||||
boost::beast::http::request<Body>&& req)
|
||||
{
|
||||
// Create the connection object and run it,
|
||||
// transferring ownership of the ugprade request.
|
||||
@@ -328,10 +330,10 @@ class wss_async_port
|
||||
// The types of the on_new_stream callbacks
|
||||
//
|
||||
using on_new_stream_cb1 =
|
||||
boost::function<void(beast::websocket::stream<socket_type>&)>;
|
||||
boost::function<void(boost::beast::websocket::stream<socket_type>&)>;
|
||||
|
||||
using on_new_stream_cb2 =
|
||||
boost::function<void(beast::websocket::stream<ssl_stream<socket_type>>&)>;
|
||||
boost::function<void(boost::beast::websocket::stream<ssl_stream<socket_type>>&)>;
|
||||
|
||||
// Reference to the server instance that made us
|
||||
server& instance_;
|
||||
@@ -361,7 +363,7 @@ public:
|
||||
should have this equivalent signature:
|
||||
@code
|
||||
template<class NextLayer>
|
||||
void callback(beast::websocket::stream<NextLayer>&);
|
||||
void callback(boost::beast::websocket::stream<NextLayer>&);
|
||||
@endcode
|
||||
In C++14 this can be accomplished with a generic lambda. In
|
||||
C++11 it will be necessary to write out a lambda manually,
|
||||
@@ -421,7 +423,7 @@ public:
|
||||
on_upgrade(
|
||||
ssl_stream<socket_type>&& stream,
|
||||
endpoint_type ep,
|
||||
beast::http::request<Body>&& req)
|
||||
boost::beast::http::request<Body>&& req)
|
||||
{
|
||||
std::make_shared<async_wss_con>(
|
||||
std::move(stream),
|
||||
|
||||
Reference in New Issue
Block a user