aboutsummaryrefslogtreecommitdiff
path: root/lib/http/server.go
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2024-03-21 15:31:44 +0700
committerShulhan <ms@kilabit.info>2024-03-21 15:31:44 +0700
commit547c4b59811091bd613564a2df5b8f3ebc72bd8f (patch)
tree43296ee3126d1989fc20952b432e5a760a655c9e /lib/http/server.go
parente892d3a24843ac88c75c7da0df10882df60fa6f7 (diff)
downloadpakakeh.go-547c4b59811091bd613564a2df5b8f3ebc72bd8f.tar.xz
lib/memfs: trim trailing slash ("/") in the path of Get method
The MemFS always store directory without slash. If caller request a directory node with slash, it will always return nil.
Diffstat (limited to 'lib/http/server.go')
-rw-r--r--lib/http/server.go20
1 files changed, 12 insertions, 8 deletions
diff --git a/lib/http/server.go b/lib/http/server.go
index 37ff71dc..56a5d35b 100644
--- a/lib/http/server.go
+++ b/lib/http/server.go
@@ -345,17 +345,11 @@ func (srv *Server) Stop(wait time.Duration) (err error) {
// [ServerOptions.EnableIndexHTML] is true, server will generate list of
// content for index.html.
func (srv *Server) getFSNode(reqPath string) (node *memfs.Node, isDir bool) {
- var (
- nodeIndexHTML *memfs.Node
- pathHTML string
- err error
- )
-
if srv.Options.Memfs == nil {
return nil, false
}
- pathHTML = path.Join(reqPath, `index.html`)
+ var err error
node, err = srv.Options.Memfs.Get(reqPath)
if err != nil {
@@ -363,6 +357,8 @@ func (srv *Server) getFSNode(reqPath string) (node *memfs.Node, isDir bool) {
return nil, false
}
+ var pathHTML = path.Join(reqPath, `index.html`)
+
node, err = srv.Options.Memfs.Get(pathHTML)
if err != nil {
pathHTML = reqPath + `.html`
@@ -375,9 +371,14 @@ func (srv *Server) getFSNode(reqPath string) (node *memfs.Node, isDir bool) {
}
if node.IsDir() {
+ var (
+ pathHTML = path.Join(reqPath, `index.html`)
+ nodeIndexHTML *memfs.Node
+ )
+
nodeIndexHTML, err = srv.Options.Memfs.Get(pathHTML)
if err == nil {
- return nodeIndexHTML, true
+ return nodeIndexHTML, false
}
if !srv.Options.EnableIndexHTML {
@@ -385,6 +386,9 @@ func (srv *Server) getFSNode(reqPath string) (node *memfs.Node, isDir bool) {
}
node.GenerateIndexHTML()
+
+ // Do not return isDir=true, to prevent the caller check and
+ // redirect the user to path with slash.
}
return node, false