summaryrefslogtreecommitdiffhomepage
path: root/https.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'https.cpp')
-rw-r--r--https.cpp62
1 files changed, 7 insertions, 55 deletions
diff --git a/https.cpp b/https.cpp
index d410bb3..25af275 100644
--- a/https.cpp
+++ b/https.cpp
@@ -5,10 +5,6 @@
#include "server.h"
#include "response.h"
-#include <boost/beast/version.hpp>
-
-#if BOOST_VERSION == 107100
-
#include <openssl/ssl.h>
#include <boost/asio/buffer.hpp>
@@ -39,65 +35,18 @@ using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp>
namespace {
-// Return a reasonable mime type based on the extension of a file.
-beast::string_view
-mime_type(beast::string_view path)
-{
- using beast::iequals;
- auto const ext = [&path]
- {
- auto const pos = path.rfind(".");
- if(pos == beast::string_view::npos)
- return beast::string_view{};
- return path.substr(pos);
- }();
- 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, ".txt")) return "text/plain";
- 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";
-}
-
// This function produces an HTTP response for the given
// request. The type of the response object depends on the
// contents of the request, so the interface requires the
// caller to pass a generic lambda for receiving the response.
-template<
- class Body, class Allocator,
- class Send>
+template<class Send>
void
handle_request(
::Server& server,
- http::request<Body, http::basic_fields<Allocator>>&& req,
+ request_type&& req,
Send&& send)
{
- 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.prepare_payload();
- }
- return send(std::move(res));
+ return send(std::move(generate_response(req, server)));
}
//------------------------------------------------------------------------------
@@ -448,6 +397,8 @@ void load_server_certificate(boost::asio::ssl::context& ctx, fs::path cert_path,
std::string cert;
if (cert_path == "") {
+ // generate dummy self signed certificate. Will be replaced by real
+ // certificate if configured upon respective session
cert =
"-----BEGIN CERTIFICATE-----\n"
"MIIDnTCCAoWgAwIBAgIULkYtO+2Ddeg+qLZ+aDQpmA5b4L0wDQYJKoZIhvcNAQEL\n"
@@ -481,6 +432,8 @@ void load_server_certificate(boost::asio::ssl::context& ctx, fs::path cert_path,
std::string key;
if (key_path == "") {
+ // generate dummy self signed certificate. Will be replaced by real
+ // certificate if configured upon respective session
key =
"-----BEGIN PRIVATE KEY-----\n"
"MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCyTW9Fi28/sT/m\n"
@@ -588,5 +541,4 @@ int Server::start()
}
} // namespace HTTPS
-#endif