static icon indicating copy to clipboard operation
static copied to clipboard

Folders are not redirected if missing a slash at the end

Open Maia-Everett opened this issue 7 years ago • 4 comments

Expected behavior

If the requested URL points to a folder with an index.html file and it is missing a slash at the end, the server should respond with a redirect with a slash added at the end.

Actual behavior

If the requested URL points to a folder with an index.html file and it is missing a slash at the end, the server does not redirect with the slash added, making the browser think that the folder name is a file name, which in turn makes relative URLs work differently depending on whether or not the slash is present.

How to reproduce

  • Download and unpack this tiny project: koa-static-folder-bug.zip
  • npm install and npm start
  • Open http://localhost:3000/folder. Observe that no redirect took place. The image of a black square is displayed, even though image.png is in the parent directory of folder/index.html.
  • Open http://localhost:3000/folder/. Observe that the image is (correctly) not displayed.

Maia-Everett avatar Jun 22 '18 09:06 Maia-Everett

I support either resolving this issue with the expected behavior or an evaluation of the expected behavior.

I spent more time than I want to admit on a wild goose change, because I did not notice the missing slash in my URLs. But, I propose an alternate expected behavior.


Expected behavior

If the requested URL points to a folder with an index.html file and it is missing a slash at the end, the server should respond with a 404, not the index.html file (because folder describes a file—a different file than index.html).


Either, help the user out completely (my interpretation of the suggestion of the original poster); or, do not halfway help the user, thus leading to unexpected behavior.

wesleyboar-fka-iosulfur avatar Jul 13 '19 17:07 wesleyboar-fka-iosulfur

Hi, do you plan to implement the expected behaviour? If not, I'll need to implement a workaround requiring me hitting the disk for every incoming request to test whether the requested resource is a directory or not. This is obviously sub-optimal since downstream, koa-send will again stat the filesystem for each request.

75lb avatar Oct 04 '19 19:10 75lb

i thought this was an option...

jonathanong avatar Apr 28 '20 04:04 jonathanong

I think this solved by this PR.

3imed-jaberi avatar May 06 '20 16:05 3imed-jaberi