aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2019-04-15 02:15:34 +0700
committerShulhan <ms@kilabit.info>2019-04-15 02:15:34 +0700
commitda60d648bb8789d63ad1707599aab0986562e8ca (patch)
treefc450fdd860af9622af460d3e727dff980f7ae6d
parent5cf76aeb90afbe6638b9526b354a33307b904a06 (diff)
downloadpakakeh.go-da60d648bb8789d63ad1707599aab0986562e8ca.tar.xz
http: allow serving directory with slash
Previously, if a directory contains "index.html" and client request the directory with slash, server will return 404. For example, "/a/index.html" accessed through "/a/" will return an error but "/a" or "/a/index.html" will return the content of "index.html". This commit fix this issue by checking if memfs.Get return an os.ErrNotExist or not. If its ErrNotExist, concat the request path with "index.html".
-rw-r--r--lib/http/server.go14
1 files changed, 13 insertions, 1 deletions
diff --git a/lib/http/server.go b/lib/http/server.go
index b8c2a0cc..15261b00 100644
--- a/lib/http/server.go
+++ b/lib/http/server.go
@@ -8,6 +8,7 @@ import (
"io/ioutil"
"log"
"net/http"
+ "os"
"path"
"sort"
"strconv"
@@ -216,7 +217,18 @@ func (srv *Server) getFSNode(reqPath string) (node *memfs.Node) {
node, e = srv.mfs.Get(reqPath)
if e != nil {
- return nil
+ if e != os.ErrNotExist {
+ log.Println("http: getFSNode: " + e.Error())
+ return nil
+ }
+
+ reqPath = path.Join(reqPath, "index.html")
+
+ node, e = srv.mfs.Get(reqPath)
+ if e != nil {
+ log.Println("http: getFSNode: " + e.Error())
+ return nil
+ }
}
if node.Mode.IsDir() {