summaryrefslogtreecommitdiffhomepage
path: root/https.cpp
diff options
context:
space:
mode:
authorRoland Reichwein <mail@reichwein.it>2020-04-09 18:30:32 +0200
committerRoland Reichwein <mail@reichwein.it>2020-04-09 18:30:32 +0200
commit0d157fb407a35f8afe6d6f0f4c2cc5cd5d5a1933 (patch)
tree86ccea82ebbe29197eacb9a85e8ec7548c5ae38c /https.cpp
parent2f42619303627db401e469e2fd65123cd794a378 (diff)
Prepared generate_page for static-files plugin
Diffstat (limited to 'https.cpp')
-rw-r--r--https.cpp53
1 files changed, 22 insertions, 31 deletions
diff --git a/https.cpp b/https.cpp
index 161efad..f312295 100644
--- a/https.cpp
+++ b/https.cpp
@@ -84,8 +84,7 @@ template<
class Send>
void
handle_request(
- const Config& config,
- const Socket& socket,
+ ::Server& server,
http::request<Body, http::basic_fields<Allocator>>&& req,
Send&& send)
{
@@ -128,9 +127,17 @@ handle_request(
return res;
};
- std::string res_data;
try {
- res_data = generate_response(req, config, socket);
+ http::response<http::string_body> res{http::status::ok, req.version()};
+ res.set(http::field::server, VersionString);
+ res.set(http::field::content_type, mime_type(extend_index_html(std::string(req.target()))));
+ res.keep_alive(req.keep_alive());
+ std::string res_data = generate_response(req, res, server);
+ if (req.method() != http::verb::head) {
+ res.body() = res_data;
+ res.content_length(res_data.size());
+ }
+ return send(std::move(res));
} catch(const bad_request_exception& ex) {
return send(bad_request(ex.what()));
} catch(const not_found_exception& ex) {
@@ -138,15 +145,6 @@ handle_request(
} catch(const server_error_exception& ex) {
return send(server_error(ex.what()));
}
-
- http::response<http::string_body> res{http::status::ok, req.version()};
- res.set(http::field::server, VersionString);
- res.set(http::field::content_type, mime_type(extend_index_html(std::string(req.target()))));
- res.content_length(res_data.size());
- res.keep_alive(req.keep_alive());
- if (req.method() != http::verb::head)
- res.body() = res_data;
- return send(std::move(res));
}
//------------------------------------------------------------------------------
@@ -220,8 +218,7 @@ class session : public std::enable_shared_from_this<session>
beast::ssl_stream<beast::tcp_stream> stream_;
beast::flat_buffer buffer_;
- const Config& m_config;
- const Socket& m_socket;
+ Server& m_server;
http::request<http::string_body> req_;
std::shared_ptr<void> res_;
send_lambda lambda_;
@@ -232,11 +229,9 @@ public:
session(
tcp::socket&& socket,
ssl::context& ctx,
- const Config& config,
- const Socket& config_socket)
+ Server& server)
: stream_(std::move(socket), ctx)
- , m_config(config)
- , m_socket(config_socket)
+ , m_server(server)
, lambda_(*this)
{
}
@@ -310,7 +305,7 @@ public:
return fail(ec, "read");
// Send the response
- handle_request(m_config, m_socket, std::move(req_), lambda_);
+ handle_request(m_server, std::move(req_), lambda_);
}
void
@@ -369,21 +364,18 @@ class listener : public std::enable_shared_from_this<listener>
net::io_context& ioc_;
ssl::context& ctx_;
tcp::acceptor acceptor_;
- const Config& m_config;
- const Socket& m_socket;
+ ::Server& m_server;
public:
listener(
net::io_context& ioc,
ssl::context& ctx,
tcp::endpoint endpoint,
- const Config& config,
- const Socket& socket)
+ Server& server)
: ioc_(ioc)
, ctx_(ctx)
, acceptor_(ioc)
- , m_config(config)
- , m_socket(socket)
+ , m_server(server)
{
beast::error_code ec;
@@ -453,8 +445,7 @@ private:
std::make_shared<session>(
std::move(socket),
ctx_,
- m_config,
- m_socket)->run();
+ m_server)->run();
}
// Accept another connection
@@ -597,7 +588,8 @@ int servername_callback(SSL *s, int *al, void *arg)
namespace HTTPS {
-Server::Server(Config& config, boost::asio::io_context& ioc, const Socket& socket): ::Server(config, ioc), m_socket(socket)
+Server::Server(Config& config, boost::asio::io_context& ioc, const Socket& socket, plugins_container_type& plugins)
+ : ::Server(config, ioc, socket, plugins)
{
for (const auto& serve_site: socket.serve_sites) {
for (const auto& site: config.Sites()) {
@@ -637,8 +629,7 @@ int Server::start()
m_ioc,
m_ctx_dummy,
tcp::endpoint{address, port},
- m_config,
- m_socket)->run();
+ *this)->run();
return EXIT_SUCCESS;
}