Skip to content
This repository has been archived by the owner on Mar 31, 2020. It is now read-only.

Commit

Permalink
Add function to maintain backwards compatibility (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
abeltay authored Feb 2, 2018
1 parent 3da71c6 commit b265293
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions web/fileserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,22 @@ import (
"strings"
)

// FileServer creates a file server that serves files from from a "Root" folder.
// FileServerHandler creates a file server that serves files from from a "Root" folder.
// It will call "NotFound" HandlerFunc if the path contains '..' or if the file cannot be found on the system.
type FileServer struct {
type FileServerHandler struct {
Root string
NotFound http.HandlerFunc
}

func (f FileServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// FileServer creates a FileServer that returns http.NotFound if the file cannot be found on the system
func FileServer(root http.Dir) http.Handler {
return FileServerHandler{
Root: string(root),
NotFound: http.NotFound,
}
}

func (f FileServerHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if containsDotDot(r.URL.Path) {
f.NotFound(w, r)
return
Expand Down

0 comments on commit b265293

Please sign in to comment.