HTTP::StaticFileHandler should use an abstraction instead of a string to serve files from.
In go we have
http.Dir that is a wrapper around a
string but it adds the
Open(name string) (File, error) method, i think something similar would be great to have in crystal, here’s my attempt at translating the same abstraction we have in go.
# https://godoc.org/net/http#FileSystem abstract class HTTP::FileSystem abstract def open(path : String) : IO end end # https://godoc.org/net/http#Dir class HTTP::Dir < HTTP::FileSystem def open(path : String) : IO # ... end end
Then HTTP::StaticFileHandler could work like this
class HTTP::StaticFileHandler def initialize(@fs : HTTP::FileSystem, fallthrough = true, directory_listing = true) @fallthrough = !!fallthrough @directory_listing = !!directory_listing end # use @fs.open to open files end
This could be implemented in a backwards compatible way by overloading
new(String) to create an
HTTP::Dir and use it.