summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--contrib/fs/gopher.go13
-rw-r--r--contrib/fs/handlers.go2
-rw-r--r--gopher/gophermap/extended.go9
-rw-r--r--gopher/gophermap/listdir.go3
-rw-r--r--spartan/serve.go2
5 files changed, 23 insertions, 6 deletions
diff --git a/contrib/fs/gopher.go b/contrib/fs/gopher.go
index 209a4ec..22cdbc3 100644
--- a/contrib/fs/gopher.go
+++ b/contrib/fs/gopher.go
@@ -29,7 +29,18 @@ func GopherDirectoryDefault(fsroot, urlroot string, settings *gophermap.FileSyst
}
handler := directoryDefault(gopher.ServerProtocol, fsroot, urlroot, false, settings.DirMaps...)
- return gophermap.ExtendMiddleware(fsroot, urlroot, settings)(handler)
+
+ // force response status to MenuType since we hit a directory default file
+ menuHandler := sr.HandlerFunc(func(ctx context.Context, request *sr.Request) *sr.Response {
+ response := handler.Handle(ctx, request)
+ if response == nil {
+ return response
+ }
+ response.Status = gopher.MenuType
+ return response
+ })
+
+ return gophermap.ExtendMiddleware(fsroot, urlroot, settings)(menuHandler)
}
// GopherDirectoryListing produces a listing of the contents of any requested directories.
diff --git a/contrib/fs/handlers.go b/contrib/fs/handlers.go
index 75422d9..02b7d38 100644
--- a/contrib/fs/handlers.go
+++ b/contrib/fs/handlers.go
@@ -79,7 +79,7 @@ func directoryDefault(
if err != nil {
return protocol.TemporaryServerError(err)
}
- return protocol.Success(filepath.Base(fpath), file)
+ return protocol.Success(fpath, file)
}
return nil
diff --git a/gopher/gophermap/extended.go b/gopher/gophermap/extended.go
index f2ca3fc..910adc0 100644
--- a/gopher/gophermap/extended.go
+++ b/gopher/gophermap/extended.go
@@ -307,7 +307,7 @@ func ExtendMiddleware(fsroot, urlroot string, settings *FileSystemSettings) sr.M
return sr.HandlerFunc(func(ctx context.Context, request *sr.Request) *sr.Response {
response := handler.Handle(ctx, request)
- if !settings.ParseExtended || response.Status != gopher.MenuType {
+ if settings == nil || response == nil || !settings.ParseExtended || response.Status != gopher.MenuType {
return response
}
@@ -322,7 +322,12 @@ func ExtendMiddleware(fsroot, urlroot string, settings *FileSystemSettings) sr.M
fpath = strings.Trim(fpath, "/")
fpath = filepath.Join(fsroot, fpath)
- doc, _, err := edoc.Compatible(filepath.Dir(fpath), *settings)
+ cwd := fpath
+ if !strings.HasSuffix(request.Path, "/") {
+ cwd = filepath.Dir(cwd)
+ }
+
+ doc, _, err := edoc.Compatible(cwd, *settings)
if err != nil {
return gopher.Error(err).Response()
}
diff --git a/gopher/gophermap/listdir.go b/gopher/gophermap/listdir.go
index a2c5214..30d7790 100644
--- a/gopher/gophermap/listdir.go
+++ b/gopher/gophermap/listdir.go
@@ -28,6 +28,7 @@ func listDir(dir string, location *url.URL, settings FileSystemSettings, hidden
for _, entry := range contents {
name := entry.Name()
+ fpath := filepath.Join(dir, name)
inf, err := entry.Info()
if err != nil {
@@ -52,7 +53,7 @@ func listDir(dir string, location *url.URL, settings FileSystemSettings, hidden
} else if c, ok := extensions[name]; ok {
code = c
} else {
- code = gopher.GuessItemType(name)
+ code = gopher.GuessItemType(fpath)
}
}
diff --git a/spartan/serve.go b/spartan/serve.go
index f2155ec..9403a15 100644
--- a/spartan/serve.go
+++ b/spartan/serve.go
@@ -8,8 +8,8 @@ import (
"io"
"net"
- "tildegit.org/tjp/sliderule/internal/types"
"tildegit.org/tjp/sliderule/internal"
+ "tildegit.org/tjp/sliderule/internal/types"
"tildegit.org/tjp/sliderule/logging"
)