Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accessing Directory #1389

Closed
th-baer opened this issue Sep 8, 2022 · 4 comments
Closed

Accessing Directory #1389

th-baer opened this issue Sep 8, 2022 · 4 comments

Comments

@th-baer
Copy link

th-baer commented Sep 8, 2022

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

@yhirose
Copy link
Owner

yhirose commented Sep 8, 2022

@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.

@th-baer
Copy link
Author

th-baer commented Sep 8, 2022

@yhirose I completely agree with that redirect is the standard solution. I hope it's not too much work,

@the-WINTERSOLDIER
Copy link

the-WINTERSOLDIER commented Oct 15, 2022

Could you assign this issue to me .I'm new to Open source Contribution and I'd like to give it a shot.

@graysuit
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants