fileserver: append repeated `hide` subdirectives instead of overwriting (#7817)
Multiple `hide` subdirectives in a file_server Caddyfile block silently overwrote each other, so only the last one took effect. Append to the list instead, so repeated entries accumulate and imported snippets can compose with site-specific hides.pull/7820/head
parent
16235cced5
commit
39c9a85f80
|
|
@ -0,0 +1,35 @@
|
||||||
|
:80
|
||||||
|
|
||||||
|
file_server {
|
||||||
|
hide first.txt
|
||||||
|
hide second.txt third.txt
|
||||||
|
}
|
||||||
|
----------
|
||||||
|
{
|
||||||
|
"apps": {
|
||||||
|
"http": {
|
||||||
|
"servers": {
|
||||||
|
"srv0": {
|
||||||
|
"listen": [
|
||||||
|
":80"
|
||||||
|
],
|
||||||
|
"routes": [
|
||||||
|
{
|
||||||
|
"handle": [
|
||||||
|
{
|
||||||
|
"handler": "file_server",
|
||||||
|
"hide": [
|
||||||
|
"first.txt",
|
||||||
|
"second.txt",
|
||||||
|
"third.txt",
|
||||||
|
"./Caddyfile"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -91,10 +91,14 @@ func (fsrv *FileServer) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
|
||||||
fsrv.FileSystem = d.Val()
|
fsrv.FileSystem = d.Val()
|
||||||
|
|
||||||
case "hide":
|
case "hide":
|
||||||
fsrv.Hide = d.RemainingArgs()
|
hide := d.RemainingArgs()
|
||||||
if len(fsrv.Hide) == 0 {
|
if len(hide) == 0 {
|
||||||
return d.ArgErr()
|
return d.ArgErr()
|
||||||
}
|
}
|
||||||
|
// Append so that repeated "hide" subdirectives accumulate
|
||||||
|
// instead of overwriting, which also lets imported snippets
|
||||||
|
// compose with site-specific hides.
|
||||||
|
fsrv.Hide = append(fsrv.Hide, hide...)
|
||||||
|
|
||||||
case "index":
|
case "index":
|
||||||
fsrv.IndexNames = d.RemainingArgs()
|
fsrv.IndexNames = d.RemainingArgs()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue