3#include <boost/asio/buffer.hpp>
4#include <boost/beast/core/bind_handler.hpp>
5#include <boost/beast/core/buffers_to_string.hpp>
12 using boost::asio::buffer;
13 using boost::beast::buffers_to_string;
14 using boost::beast::bind_front_handler;
26 file_contents(
const std::filesystem::path& path)
29 if (!std::filesystem::is_regular_file(path))
35 std::ifstream file(path, std::ios::in | std::ios::binary);
40 const std::size_t& size = std::filesystem::file_size(path);
41 std::string content(size,
'\0');
42 file.read(content.data(), size);
62 if (c >=
'0' && c <=
'9')
65 else if (c >=
'a' && c <=
'f')
68 else if (c >=
'A' && c <=
'F')
87 std::vector<std::string_view>
88 split(std::string_view str, std::string_view delimiter)
95 if (delimiter.empty())
99 std::vector<std::string_view> parts;
100 std::string_view::size_type pos = 0;
101 while (pos != std::string_view::npos) {
103 const auto pos_found = str.find(delimiter, pos);
106 if (pos_found == 0) {
107 pos += delimiter.size();
112 parts.emplace_back(str.substr(pos, pos_found-pos));
115 if (pos_found + delimiter.size() >= str.size())
119 if (pos_found == std::string_view::npos)
121 pos = pos_found + delimiter.size();
141 url_decode(std::string& str)
144 for (
size_t r = 0 ; r < str.size() ; ++r) {
147 v = hex2dec(str[++r]) << 4;
148 v |= hex2dec(str[++r]);
167 mime_type(
const std::filesystem::path& path)
170 const std::filesystem::path& ext = path.extension();
172 if (ext ==
".7z")
return "application/x-7z-compressed";
173 if (ext ==
".bin")
return "application/octet-stream";
174 if (ext ==
".bmp")
return "image/bmp";
175 if (ext ==
".bz")
return "application/x-bzip";
176 if (ext ==
".bz2")
return "application/x-bzip2";
177 if (ext ==
".css")
return "text/css";
178 if (ext ==
".css.min")
return "text/css";
179 if (ext ==
".csv")
return "text/csv";
180 if (ext ==
".gif")
return "image/gif";
181 if (ext ==
".gz")
return "application/gzip";
182 if (ext ==
".ico")
return "image/vnd.microsoft.icon";
183 if (ext ==
".htm")
return "text/html";
184 if (ext ==
".html")
return "text/html";
185 if (ext ==
".mp3")
return "audio/mpeg";
186 if (ext ==
".mp4")
return "video/mp4";
187 if (ext ==
".mpeg")
return "video/mpeg";
188 if (ext ==
".rar")
return "application/vnd.rar";
189 if (ext ==
".php")
return "text/html";
190 if (ext ==
".txt")
return "text/plain";
191 if (ext ==
".js")
return "application/javascript";
192 if (ext ==
".json")
return "application/json";
193 if (ext ==
".xml")
return "application/xml";
194 if (ext ==
".swf")
return "application/x-shockwave-flash";
195 if (ext ==
".flv")
return "video/x-flv";
196 if (ext ==
".png")
return "image/png";
197 if (ext ==
".jpe")
return "image/jpeg";
198 if (ext ==
".jpeg")
return "image/jpeg";
199 if (ext ==
".jpg")
return "image/jpeg";
200 if (ext ==
".tiff")
return "image/tiff";
201 if (ext ==
".tif")
return "image/tiff";
202 if (ext ==
".svg")
return "image/svg+xml";
203 if (ext ==
".svgz")
return "image/svg+xml";
204 if (ext ==
".zip")
return "application/zip";
207 return "application/octet-stream";
Definition: controller.hpp:31
std::vector< std::string_view > split(std::string_view str, std::string_view delimiter)
Definition: utils.hpp:88