Accessing Directory
th-baer opened this issue · 4 comments
Hello,
I was testing you library and I had a problem to access a directory http://localhost/dir
Looking into the code I noticed that you check for / at the end so http://localhost/dir/ did work.
I would suggest to change the code to handle this like:
inline bool Server::handle_file_request(const Request &req, Response &res,
bool head) {
for (const auto &entry : base_dirs_) {
// Prefix match
if (!req.path.compare(0, entry.mount_point.size(), entry.mount_point)) {
std::string sub_path = "/" + req.path.substr(entry.mount_point.size());
if (detail::is_valid_path(sub_path)) {
auto path = entry.base_dir + sub_path;
if (path.back() == '/') { path += "index.html"; }
else if (detail::is_dir(path)) { path += "/index.html"; }
Only the last line was added.
Best Regadrs,
Thomas
@th-baer, thanks for the feedback. I understand what you would like to do, but I don't prefer the solution to take /dir
as /dir/
. I think most HTTP servers (like 'python -m http.server') use redirection (301) from /dir
to /dir/
. I'll take a look at the approach instead.
@yhirose I completely agree with that redirect is the standard solution. I hope it's not too much work,
Could you assign this issue to me .I'm new to Open source Contribution and I'd like to give it a shot.
Could you assign this issue to me .I'm new to Open source Contribution and I'd like to give it a shot.
Why asking ? go fork repo, do contribution and create pull request here. lol