engine: resources: The http:file resource should allow directories

This expands the use of the http:file resource to allow it to be used as
a directory root.
This commit is contained in:
James Shubin
2024-01-28 23:13:19 -05:00
parent c78ef29bda
commit 7e1a4dea6c
2 changed files with 116 additions and 4 deletions

46
examples/lang/http1.mcl Normal file
View File

@@ -0,0 +1,46 @@
$root = "/tmp/httproot/"
file $root {
state => $const.res.file.state.exists,
}
file "${root}file0" {
content => "i'm file0 in ${root}\n",
state => $const.res.file.state.exists,
}
file "${root}file1" {
content => "i'm file1 in ${root}\n",
state => $const.res.file.state.exists,
}
file "${root}dir1/" {
state => $const.res.file.state.exists,
}
file "${root}dir2/" {
state => $const.res.file.state.exists,
}
file "${root}dir1/file2" {
content => "i'm file2 in ${root}dir1/\n",
state => $const.res.file.state.exists,
}
file "${root}dir2/file3" {
content => "i'm file3 in ${root}dir2/\n",
state => $const.res.file.state.exists,
}
# test with: wget -q -O - http://127.0.0.1:8080/secret/folder/file1
http:server ":8080" { # by default http uses :80 but using :8080 avoids needing root!
#address => ":8080", # you can override the name like this
#timeout => 60, # add a timeout (seconds)
#root => $root, # add a httproot (optional)
}
# you can add a raw file like this...
http:file "/file1" {
data => "hello, world, i'm file1 and i don't exist on disk!\n",
}
# this pulls in a whole folder, since path is a folder!
http:file "/secret/folder/" {
path => "${root}",
Depend => File["${root}"], # TODO: add autoedges
}