Skip to content

Commit

Permalink
Merge pull request #24 from usedbytes/dir_handling
Browse files Browse the repository at this point in the history
Fixup directory handling
  • Loading branch information
briandowns authored Jun 28, 2017
2 parents e04fda8 + 7578e4d commit 342c020
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,14 @@ func (h *httpServer) ServeHTTP(w http.ResponseWriter, req *http.Request) {
setHeaders(w)

if stat.IsDir() {
if escapedPath[len(escapedPath) - 1] != '/' {
// Redirect all directory requests to ensure they end with a slash
http.Redirect(w, req, escapedPath + "/", http.StatusFound)
rd.Status = http.StatusFound;
fmt.Println(rd)
return
}

contents, err := file.Readdir(-1)
if err != nil {
rd.Status = http.StatusInternalServerError
Expand Down Expand Up @@ -203,7 +211,7 @@ func (h *httpServer) ServeHTTP(w http.ResponseWriter, req *http.Request) {
"port": h.Port,
"relativePath": escapedPath,
"goVersion": runtime.Version(),
"parentDirectory": path.Dir(escapedPath),
"parentDirectory": path.Clean(escapedPath + "/.."),
})

fmt.Println(rd)
Expand Down

0 comments on commit 342c020

Please sign in to comment.