aboutsummaryrefslogtreecommitdiffhomepage
path: root/modules/caddyhttp/fileserver/caddyfile.go
diff options
context:
space:
mode:
authorkylosus <[email protected]>2024-04-01 21:12:40 +0300
committerGitHub <[email protected]>2024-04-01 18:12:40 +0000
commit45132c5b24b411afbf90e8f897a1598d4eca790f (patch)
tree3232c948752171908ddd64bf610c8d5a1721d470 /modules/caddyhttp/fileserver/caddyfile.go
parent1217449609050471dfb70fdf35c9a22d738e2bef (diff)
downloadcaddy-45132c5b24b411afbf90e8f897a1598d4eca790f.tar.gz
caddy-45132c5b24b411afbf90e8f897a1598d4eca790f.zip
caddyhttp: Add plaintext response to `file_server browse` (#6093)
* Added plaintext support to file_server browser This commit is twofold: First it adds a new optional field, `return_type`, to `browser` for setting the default format of the returned index (html, json or plaintext). This is used when the `Accept` header is set to `/*`. Second, it adds a preliminary `text/plain` support to the `file_server` browser that returns a text representation of the file system, when an `Accept: text/plain` header is present, with the behavior discussed above. * Added more details and better formatting to plaintext browser * Replaced returnType conditions with a switch statement * Simplify --------- Co-authored-by: Matt Holt <[email protected]>
Diffstat (limited to 'modules/caddyhttp/fileserver/caddyfile.go')
-rw-r--r--modules/caddyhttp/fileserver/caddyfile.go12
1 files changed, 7 insertions, 5 deletions
diff --git a/modules/caddyhttp/fileserver/caddyfile.go b/modules/caddyhttp/fileserver/caddyfile.go
index 6ad9190f3..d90e4f9a0 100644
--- a/modules/caddyhttp/fileserver/caddyfile.go
+++ b/modules/caddyhttp/fileserver/caddyfile.go
@@ -113,13 +113,15 @@ func (fsrv *FileServer) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
fsrv.Browse = new(Browse)
d.Args(&fsrv.Browse.TemplateFile)
for nesting := d.Nesting(); d.NextBlock(nesting); {
- if d.Val() != "reveal_symlinks" {
+ switch d.Val() {
+ case "reveal_symlinks":
+ if fsrv.Browse.RevealSymlinks {
+ return d.Err("Symlinks path reveal is already enabled")
+ }
+ fsrv.Browse.RevealSymlinks = true
+ default:
return d.Errf("unknown subdirective '%s'", d.Val())
}
- if fsrv.Browse.RevealSymlinks {
- return d.Err("Symlinks path reveal is already enabled")
- }
- fsrv.Browse.RevealSymlinks = true
}
case "precompressed":