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

fileserver tries to read directories #256

Closed
cleverdripper opened this issue Jul 6, 2013 · 2 comments
Closed

fileserver tries to read directories #256

cleverdripper opened this issue Jul 6, 2013 · 2 comments

Comments

@cleverdripper
Copy link

If you try to request a directory from an HTTP server that routes a request for a directory to the handler returned by serveStaticFiles (not counting the root directory) it will try to read the directory like a file and fail.

You will get a similar error to this:

Error after page has been written: object.Exception@../../.dub/packages/vibe-d-0.7.16/source/vibe/core/drivers/threadedfile.d(171): Failed to read data from disk.
----------------
./main(pure @safe bool std.exception.enforce!(bool).enforce(bool, lazy const(char)[], immutable(char)[], ulong)+0x6b) [0x55537f]
./main(void vibe.core.drivers.threadedfile.ThreadedFileStream.read(ubyte[])+0x133) [0x63eee7]
./main(void vibe.core.stream.OutputStream.writeDefault(vibe.core.stream.InputStream, ulong, bool)+0x135) [0x630ab1]
./main(void vibe.stream.counting.CountingOutputStream.write(vibe.core.stream.InputStream, ulong, bool)+0x7a) [0x5b7fae]
./main(void vibe.http.fileserver.sendFile(vibe.http.server.HTTPServerRequest, vibe.http.server.HTTPServerResponse, vibe.inet.path.Path, vibe.http.fileserver.HTTPFileServerSettings)+0x7c5) [0x5e9d39]
./main(void delegate(vibe.http.server.HTTPServerRequest, vibe.http.server.HTTPServerResponse) vibe.http.fileserver.serveStaticFiles(vibe.inet.path.Path, vibe.http.fileserver.HTTPFileServerSettings).void callback(vibe.http.server.HTTPServerRequest, vibe.http.server.HTTPServerResponse)+0x2ce) [0x5e931a]
./main(void vibe.http.router.URLRouter.handleRequest(vibe.http.server.HTTPServerRequest, vibe.http.server.HTTPServerResponse)+0x179) [0x5d930d]
./main(bool vibe.http.server.handleRequest(vibe.core.stream.Stream, immutable(char)[], vibe.http.server.HTTPServerListener, ref vibe.http.server.HTTPServerSettings, ref bool)+0x1671) [0x5dff85]
./main(void vibe.http.server.handleHTTPConnection(vibe.core.net.TCPConnection, vibe.http.server.HTTPServerListener)+0x143) [0x5de84f]
./main(void vibe.http.server.listenHTTPPlain(vibe.http.server.HTTPServerSettings, void delegate(vibe.http.server.HTTPServerRequest, vibe.http.server.HTTPServerResponse)).void doListen(vibe.http.server.HTTPServerSettings, vibe.http.server.HTTPServerListener, immutable(char)[]).void __lambda37(vibe.core.net.TCPConnection)+0x2c) [0x5dafb0]
./main(extern (C) nothrow void vibe.core.drivers.libevent2_tcp.onConnect(int, short, void*).void ClientTask.execute()+0x2c7) [0x636033]
./main(void vibe.core.core.CoreTask.run()+0xee) [0x60f892]
./main(void core.thread.Fiber.run()+0x2a) [0x6755ba]
./main(fiber_entryPoint+0x61) [0x6754c5]
[(nil)]

The enforce is triggered here https://github.com/rejectedsoftware/vibe.d/blob/v0.7.16/source/vibe/core/drivers/threadedfile.d#L171

I fixed this issue by inserting

if ( isDir(pathstr) )
    return;

On line 132 of fileserver.d.

I am using 0.7.16 with dmd 2.063.2 on Arch Linux 64 bit.

@s-ludwig
Copy link
Member

s-ludwig commented Jul 6, 2013

Sounds like a good solution. Some kind of configurable directory index support could also be nice at some point.

@cleverdripper
Copy link
Author

@s-ludwig What kind of directory index support do you think would be good? I'd like to work on it if no one else is already.

I think it should be where the user can specify to either

  1. use the default directory index
  2. specify a template file to use (and the template will be provided certain parameters like the directory requested and a range for iterating the contents of the directory)
  3. specify the name of the file in the directory that should be sent when a directory is requested (for things like index.html) or
  4. specify a callback to be called when a directory is requested

all by setting things in the HTTPFileServerSettings used with the fileserver.

If that's agreeable, should the default directory listing page be a diet template or should it be generated with code? If a template, where should the file go? I don't know what the paths are that are searched by render. It may be better to have the template be a string-literal in the code, but I'm not sure how to render a string literal instead of a file. Maybe that should be added too.

Somewhat unrelated, but I don't know what use case triggered the problems you guys were having with render that warranted renderCompat, but I'm not having any problems with it in DMD 2.063.2. Maybe a version should wrap the warning messages for using it, unless I'm just somehow dodging otherwise buggy behavior.

Also do you prefer pull requests or patchsets for contributions?

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

No branches or pull requests

2 participants