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 std::string content{std::istreambuf_iterator<char>(file), std::istreambuf_iterator<char>()};
58 hex2dec(std::uint8_t c)
60 if (c >=
'0' && c <=
'9')
63 else if (c >=
'a' && c <=
'f')
66 else if (c >=
'A' && c <=
'F')
85 std::vector<std::string_view>
86 split(std::string_view str, std::string_view delimiter)
93 if (delimiter.empty())
97 std::vector<std::string_view> parts;
98 std::string_view::size_type pos = 0;
99 while (pos != std::string_view::npos) {
101 const auto pos_found = str.find(delimiter, pos);
104 if (pos_found == 0) {
105 pos += delimiter.size();
110 parts.emplace_back(str.substr(pos, pos_found-pos));
113 if (pos_found + delimiter.size() >= str.size())
117 if (pos_found == std::string_view::npos)
119 pos = pos_found + delimiter.size();
140 url_decode(std::string& str)
143 for (
size_t r = 0 ; r < str.size() ; ++r) {
146 v = hex2dec(str[++r]) << 4;
147 v |= hex2dec(str[++r]);
166 mime_type(
const std::filesystem::path& path)
169 const std::filesystem::path& ext = path.extension();
171 if (ext ==
".7z")
return "application/x-7z-compressed";
172 if (ext ==
".bin")
return "application/octet-stream";
173 if (ext ==
".bmp")
return "image/bmp";
174 if (ext ==
".bz")
return "application/x-bzip";
175 if (ext ==
".bz2")
return "application/x-bzip2";
176 if (ext ==
".css")
return "text/css";
177 if (ext ==
".css.min")
return "text/css";
178 if (ext ==
".csv")
return "text/csv";
179 if (ext ==
".gif")
return "image/gif";
180 if (ext ==
".gz")
return "application/gzip";
181 if (ext ==
".ico")
return "image/vnd.microsoft.icon";
182 if (ext ==
".htm")
return "text/html";
183 if (ext ==
".html")
return "text/html";
184 if (ext ==
".mp3")
return "audio/mpeg";
185 if (ext ==
".mp4")
return "video/mp4";
186 if (ext ==
".mpeg")
return "video/mpeg";
187 if (ext ==
".rar")
return "application/vnd.rar";
188 if (ext ==
".php")
return "text/html";
189 if (ext ==
".txt")
return "text/plain";
190 if (ext ==
".js")
return "application/javascript";
191 if (ext ==
".json")
return "application/json";
192 if (ext ==
".xml")
return "application/xml";
193 if (ext ==
".swf")
return "application/x-shockwave-flash";
194 if (ext ==
".flv")
return "video/x-flv";
195 if (ext ==
".png")
return "image/png";
196 if (ext ==
".jpe")
return "image/jpeg";
197 if (ext ==
".jpeg")
return "image/jpeg";
198 if (ext ==
".jpg")
return "image/jpeg";
199 if (ext ==
".tiff")
return "image/tiff";
200 if (ext ==
".tif")
return "image/tiff";
201 if (ext ==
".svg")
return "image/svg+xml";
202 if (ext ==
".svgz")
return "image/svg+xml";
203 if (ext ==
".zip")
return "application/zip";
206 return "application/octet-stream";
Definition: controller.hpp:32
std::vector< std::string_view > split(std::string_view str, std::string_view delimiter)
Definition: utils.hpp:86