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

Return 404 error or page if requested directory does not contain index.html #294

Closed
mojavelinux opened this issue May 22, 2013 · 3 comments
Labels
Milestone

Comments

@mojavelinux
Copy link
Member

Awestruct rewrites the path from /foobar/ to /foobar/index.html then checks to see if index.html exists in that directory. If index.html does not exist, then it continues the request with the original path /foobar/, but treats it as a file.

if ( File.exist?( fs_path ) ) {
  body = read_content( fs_path ) # failure occurs here
}

When fs_path is a directory (e.g., /foobar/), the code above leads to the error that the content is a directory. It should, instead, follow the 404 path.

if ( File.file?( fs_path ) ) {
  body = read_content( fs_path ) # now we are sure it's a file and we can read it
}

We have to be careful with File.exist?. It does not check for files only, but rather files or directories.

@LightGuard
Copy link
Member

Where is this? Is it in the rack config?

@mojavelinux
Copy link
Member Author

Oh, right, forgot to mention the file.

/lib/awestruct/rack/app.rb:66

@LightGuard
Copy link
Member

Care to send a PR?

LightGuard added a commit that referenced this issue May 28, 2013
resolves #294 gracefully handle directory w/ no index file

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

No branches or pull requests

2 participants