mirror of
https://github.com/r-smith/deceptifeed.git
synced 2025-10-23 08:22:21 +00:00
Add noDirectoryFS wrapper to disable directory listings from http.FileServerFS. This is used when the HTTP honeypot is configured to serve custom content from a specified directory.
30 lines
724 B
Go
30 lines
724 B
Go
package httpserver
|
|
|
|
import "io/fs"
|
|
|
|
// noDirectoryFS is a wrapper around fs.FS that disables directory listings.
|
|
type noDirectoryFS struct {
|
|
fs fs.FS
|
|
}
|
|
|
|
// Open opens the named file from the underlying fs.FS. The file is wrapped in
|
|
// a noReadDirFile to disable directory listings.
|
|
func (fs noDirectoryFS) Open(name string) (fs.File, error) {
|
|
f, err := fs.fs.Open(name)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return noReadDirFile{f}, nil
|
|
}
|
|
|
|
// noReadDirFile wraps fs.File and overrides ReadDir to disable directory
|
|
// listings.
|
|
type noReadDirFile struct {
|
|
fs.File
|
|
}
|
|
|
|
// ReadDir always returns an error to disable directory listings.
|
|
func (noReadDirFile) ReadDir(int) ([]fs.DirEntry, error) {
|
|
return nil, fs.ErrInvalid
|
|
}
|