generated from Sithas/conan_template
Вынесена функция
(cherry picked from commit 4814cdcabb06c47fb6258b0031d97e2d5bff24b2)
This commit is contained in:
+6
-54
@@ -17,65 +17,17 @@
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
#include "./helpers/helpers.h"
|
||||
|
||||
namespace beast = boost::beast; // from <boost/beast.hpp>
|
||||
namespace http = beast::http; // from <boost/beast/http.hpp>
|
||||
namespace websocket = beast::websocket; // from <boost/beast/websocket.hpp>
|
||||
namespace net = boost::asio; // from <boost/asio.hpp>
|
||||
using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp>
|
||||
using namespace uad;
|
||||
|
||||
// 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";
|
||||
}
|
||||
|
||||
|
||||
// Append an HTTP rel-path to a local filesystem path.
|
||||
// The returned path is normalized for the platform.
|
||||
@@ -178,7 +130,7 @@ void handle_request(beast::string_view doc_root,
|
||||
if (req.method() == http::verb::head) {
|
||||
http::response<http::empty_body> res{http::status::ok, req.version()};
|
||||
res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
|
||||
res.set(http::field::content_type, mime_type(path));
|
||||
res.set(http::field::content_type, MimeType(path));
|
||||
res.content_length(size);
|
||||
res.keep_alive(req.keep_alive());
|
||||
return send(std::move(res));
|
||||
@@ -189,7 +141,7 @@ void handle_request(beast::string_view doc_root,
|
||||
std::piecewise_construct, std::make_tuple(std::move(body)),
|
||||
std::make_tuple(http::status::ok, req.version())};
|
||||
res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
|
||||
res.set(http::field::content_type, mime_type(path));
|
||||
res.set(http::field::content_type, MimeType(path));
|
||||
res.content_length(size);
|
||||
res.keep_alive(req.keep_alive());
|
||||
return send(std::move(res));
|
||||
|
||||
Reference in New Issue
Block a user