Skip to content

Commit

Permalink
Improve list dir and fix utf8 char
Browse files Browse the repository at this point in the history
  • Loading branch information
Jackarain committed Nov 15, 2023
1 parent 708f02b commit 5851f95
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions httpd/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ R"x1x(<html>
</html>
)x1x";

inline const char* version_string = "nginx/1.20.2";

const static std::map<std::string, std::string> global_mimes =
{
{ ".html", "text/html; charset=utf-8" },
Expand Down Expand Up @@ -222,6 +224,18 @@ inline ranges get_ranges(std::string range)
return result;
}

inline std::string server_date_string()
{
auto time = std::time(nullptr);
auto gmt = gmtime((const time_t*)&time);

std::string str(64, '\0');
auto ret = strftime((char*)str.data(), 64, "%a, %d %b %Y %H:%M:%S GMT", gmt);
str.resize(ret);

return str;
}

inline awaitable_void read_from_stdin()
{
auto ex = co_await net::this_coro::executor;
Expand Down Expand Up @@ -525,7 +539,7 @@ inline std::vector<std::wstring> format_path_list(const std::set<fs::path>& path
{
auto leaf = boost::nowide::narrow(item.filename().wstring());
leaf = leaf + "/";
rpath.assign(leaf.begin(), leaf.end());
rpath = boost::nowide::widen(leaf);
int width = 50 - rpath.size();
width = width < 0 ? 0 : width;
std::wstring space(width, L' ');
Expand All @@ -546,7 +560,7 @@ inline std::vector<std::wstring> format_path_list(const std::set<fs::path>& path
else
{
auto leaf = boost::nowide::narrow(item.filename().wstring());
rpath.assign(leaf.begin(), leaf.end());
rpath = boost::nowide::widen(leaf);
int width = 50 - (int)rpath.size();
width = width < 0 ? 0 : width;
std::wstring space(width, L' ');
Expand Down Expand Up @@ -660,7 +674,11 @@ inline awaitable_void dir_session(
req.version()
};

res.set(http::field::server, version_string);
res.set(http::field::date, server_date_string());
res.set(http::field::content_type, "text/html; charset=UTF-8");
res.keep_alive(req.keep_alive());
res.content_length(body.size());
res.body() = boost::nowide::narrow(body);
res.prepare_payload();

Expand Down

0 comments on commit 5851f95

Please sign in to comment.