Group common example headers

This commit is contained in:
Vinnie Falco committed 2017-07-20 08:15:29 -07:00
1 parent 84d7601bdf
commit bb1dd72638
27 files changed
+143 -88

No files matched your search

@@ -5,8 +5,8 @@
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef BEAST_EXAMPLE_SERVER_DETECT_SSL_HPP
#define BEAST_EXAMPLE_SERVER_DETECT_SSL_HPP
#ifndef BEAST_EXAMPLE_COMMON_DETECT_SSL_HPP
#define BEAST_EXAMPLE_COMMON_DETECT_SSL_HPP
#include <boost/assert.hpp>
#include <boost/config.hpp>
@@ -5,8 +5,8 @@
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef BEAST_EXAMPLE_HTTP_SERVER_FILE_BODY_HPP
#define BEAST_EXAMPLE_HTTP_SERVER_FILE_BODY_HPP
#ifndef BEAST_EXAMPLE_COMMON_FILE_BODY_HPP
#define BEAST_EXAMPLE_COMMON_FILE_BODY_HPP
#include <beast/core/error.hpp>
#include <beast/http/message.hpp>
+46
View File
@@ -0,0 +1,46 @@
//
// 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)
//
#ifndef BEAST_EXAMPLE_COMMON_MIME_TYPES_HPP
#define BEAST_EXAMPLE_COMMON_MIME_TYPES_HPP
#include <beast/core/string.hpp>
#include <boost/filesystem/path.hpp>
// Return a reasonable mime type based on the extension of a file.
//
template<class = void>
beast::string_view
mime_type(boost::filesystem::path const& path)
{
using beast::iequals;
auto const ext = path.extension().string();
if(iequals(ext, ".txt")) return "text/plain";
if(iequals(ext, ".htm")) return "text/html";
if(iequals(ext, ".html")) return "text/html";
if(iequals(ext, ".php")) return "text/html";
if(iequals(ext, ".css")) return "text/css";
if(iequals(ext, ".js")) return "application/javascript";
if(iequals(ext, ".json")) return "application/json";
if(iequals(ext, ".xml")) return "application/xml";
if(iequals(ext, ".swf")) return "application/x-shockwave-flash";
if(iequals(ext, ".flv")) return "video/x-flv";
if(iequals(ext, ".png")) return "image/png";
if(iequals(ext, ".jpe")) return "image/jpeg";
if(iequals(ext, ".jpeg")) return "image/jpeg";
if(iequals(ext, ".jpg")) return "image/jpeg";
if(iequals(ext, ".gif")) return "image/gif";
if(iequals(ext, ".bmp")) return "image/bmp";
if(iequals(ext, ".ico")) return "image/vnd.microsoft.icon";
if(iequals(ext, ".tiff")) return "image/tiff";
if(iequals(ext, ".tif")) return "image/tiff";
if(iequals(ext, ".svg")) return "image/svg+xml";
if(iequals(ext, ".svgz")) return "image/svg+xml";
return "application/text";
}
#endif
@@ -5,13 +5,12 @@
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef BEAST_EXAMPLE_SERVER_RFC7231_HPP
#define BEAST_EXAMPLE_SERVER_RFC7231_HPP
#ifndef BEAST_EXAMPLE_COMMON_RFC7231_HPP
#define BEAST_EXAMPLE_COMMON_RFC7231_HPP
#include <beast/core/string.hpp>
#include <beast/http/message.hpp>
namespace framework {
namespace rfc7231 {
// This aggregates a collection of algorithms
@@ -36,6 +35,5 @@ is_expect_100_continue(beast::http::request<
}
} // rfc7231
} // framework
#endif
@@ -5,8 +5,8 @@
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef BEAST_EXAMPLE_SERVER_SSL_STREAM_HPP
#define BEAST_EXAMPLE_SERVER_SSL_STREAM_HPP
#ifndef BEAST_EXAMPLE_COMMON_SSL_STREAM_HPP
#define BEAST_EXAMPLE_COMMON_SSL_STREAM_HPP
// This include is necessary to work with `ssl::stream` and `beast::websocket::stream`
#include <beast/websocket/ssl.hpp>
@@ -5,10 +5,8 @@
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef BEAST_EXAMPLE_SERVER_WRITE_MSG_HPP
#define BEAST_EXAMPLE_SERVER_WRITE_MSG_HPP
#include "server.hpp"
#ifndef BEAST_EXAMPLE_COMMON_WRITE_MSG_HPP
#define BEAST_EXAMPLE_COMMON_WRITE_MSG_HPP
#include <beast/core/async_result.hpp>
#include <beast/core/handler_ptr.hpp>
@@ -20,8 +18,6 @@
#include <boost/asio/handler_continuation_hook.hpp>
#include <boost/asio/handler_invoke_hook.hpp>
namespace framework {
namespace detail {
/** Composed operation to send an HTTP message
@@ -108,7 +104,7 @@ public:
// This gets called when beast::http::async_write completes
//
void
operator()(error_code ec)
operator()(beast::error_code ec)
{
d_.invoke(ec);
}
@@ -196,7 +192,7 @@ template<
class AsyncWriteStream,
bool isRequest, class Body, class Fields,
class WriteHandler>
beast::async_return_type<WriteHandler, void(error_code)>
beast::async_return_type<WriteHandler, void(beast::error_code)>
async_write_msg(
AsyncWriteStream& stream,
beast::http::message<isRequest, Body, Fields>&& msg,
@@ -212,11 +208,11 @@ async_write_msg(
static_assert(beast::http::is_body_reader<Body>::value,
"BodyReader requirements not met");
beast::async_completion<WriteHandler, void(error_code)> init{handler};
beast::async_completion<WriteHandler, void(beast::error_code)> init{handler};
detail::write_msg_op<
::detail::write_msg_op<
AsyncWriteStream,
beast::handler_type<WriteHandler, void(error_code)>,
beast::handler_type<WriteHandler, void(beast::error_code)>,
isRequest, Body, Fields>{
init.completion_handler,
stream,
@@ -225,6 +221,4 @@ async_write_msg(
return init.result.get();
}
} // framework
#endif
+6
View File
@@ -3,9 +3,15 @@
GroupSources(include/beast beast)
GroupSources(example/server-framework "/")
GroupSources(example/common "common")
file(GLOB_RECURSE SERVER_INCLUDES
${PROJECT_SOURCE_DIR}/example/server-framework/*.hpp
)
add_executable (server-framework
${BEAST_INCLUDES}
${COMMON_INCLUDES}
${SERVER_INCLUDES}
main.cpp
)
+2 -32
View File
@@ -8,8 +8,9 @@
#ifndef BEAST_EXAMPLE_SERVER_FILE_SERVICE_HPP
#define BEAST_EXAMPLE_SERVER_FILE_SERVICE_HPP
#include "file_body.hpp"
#include "framework.hpp"
#include "../common/file_body.hpp"
#include "../common/mime_types.hpp"
#include <beast/core/string.hpp>
#include <beast/http/empty_body.hpp>
@@ -182,37 +183,6 @@ public:
}
private:
// Return a reasonable mime type based on the extension of a file.
//
beast::string_view
mime_type(boost::filesystem::path const& path) const
{
using beast::iequals;
auto const ext = path.extension().string();
if(iequals(ext, ".txt")) return "text/plain";
if(iequals(ext, ".htm")) return "text/html";
if(iequals(ext, ".html")) return "text/html";
if(iequals(ext, ".php")) return "text/html";
if(iequals(ext, ".css")) return "text/css";
if(iequals(ext, ".js")) return "application/javascript";
if(iequals(ext, ".json")) return "application/json";
if(iequals(ext, ".xml")) return "application/xml";
if(iequals(ext, ".swf")) return "application/x-shockwave-flash";
if(iequals(ext, ".flv")) return "video/x-flv";
if(iequals(ext, ".png")) return "image/png";
if(iequals(ext, ".jpe")) return "image/jpeg";
if(iequals(ext, ".jpeg")) return "image/jpeg";
if(iequals(ext, ".jpg")) return "image/jpeg";
if(iequals(ext, ".gif")) return "image/gif";
if(iequals(ext, ".bmp")) return "image/bmp";
if(iequals(ext, ".ico")) return "image/vnd.microsoft.icon";
if(iequals(ext, ".tiff")) return "image/tiff";
if(iequals(ext, ".tif")) return "image/tiff";
if(iequals(ext, ".svg")) return "image/svg+xml";
if(iequals(ext, ".svgz")) return "image/svg+xml";
return "application/text";
}
// Return an HTTP Not Found response
//
template<class Body, class Fields>
+3 -2
View File
@@ -11,9 +11,10 @@
#include "server.hpp"
#include "http_base.hpp"
#include "rfc7231.hpp"
#include "service_list.hpp"
#include "write_msg.hpp"
#include "../common/rfc7231.hpp"
#include "../common/write_msg.hpp"
#include <beast/core/flat_buffer.hpp>
#include <beast/http/dynamic_body.hpp>
+3 -2
View File
@@ -11,9 +11,10 @@
#include "server.hpp"
#include "http_base.hpp"
#include "rfc7231.hpp"
#include "service_list.hpp"
#include "write_msg.hpp"
#include "../common/rfc7231.hpp"
#include "../common/write_msg.hpp"
#include <beast/core/flat_buffer.hpp>
#include <beast/core/handler_ptr.hpp>
+2 -1
View File
@@ -10,7 +10,8 @@
#include "http_sync_port.hpp"
#include "http_async_port.hpp"
#include "ssl_stream.hpp"
#include "../common/ssl_stream.hpp"
#include <boost/asio/ssl.hpp>
+2 -1
View File
@@ -8,12 +8,13 @@
#ifndef BEAST_EXAMPLE_SERVER_MULTI_PORT_HPP
#define BEAST_EXAMPLE_SERVER_MULTI_PORT_HPP
#include "detect_ssl.hpp"
#include "ws_async_port.hpp"
#include "http_async_port.hpp"
#include "https_ports.hpp"
#include "wss_ports.hpp"
#include "../common/detect_ssl.hpp"
#include <beast/core.hpp>
#include <boost/function.hpp>
+2 -1
View File
@@ -10,7 +10,8 @@
#include "ws_sync_port.hpp"
#include "ws_async_port.hpp"
#include "ssl_stream.hpp"
#include "../common/ssl_stream.hpp"
#include <boost/asio/ssl.hpp>
#include <boost/function.hpp>