http: improved directory listing with new template from Caddy project

This includes a new directory listing template which was originally
from the Caddy project (used with permission and copyright attribution).

This is used whenever we serve directory listings so `rclone serve
http`, `rclone serve webdav` and `rclone rcd --rc-serve`

This also modifies the tests so they work with the original template which
is easier to debug.
This commit is contained in:
calisro
2020-05-08 11:15:21 -04:00
committed by GitHub
parent 97f6f8fe19
commit c80b6d96dd
12 changed files with 457 additions and 21 deletions

View File

@@ -22,6 +22,7 @@ import (
const (
testBindAddress = "localhost:0"
testTemplate = "testdata/golden/testindex.html"
testFs = "testdata/files"
remoteURL = "[" + testFs + "]/" // initial URL path to fetch from that remote
)
@@ -31,6 +32,7 @@ const (
func TestRcServer(t *testing.T) {
opt := rc.DefaultOpt
opt.HTTPOptions.ListenAddr = testBindAddress
opt.HTTPOptions.Template = testTemplate
opt.Enabled = true
opt.Serve = true
opt.Files = testFs
@@ -82,6 +84,7 @@ type testRun struct {
// Run a suite of tests
func testServer(t *testing.T, tests []testRun, opt *rc.Options) {
mux := http.NewServeMux()
opt.HTTPOptions.Template = testTemplate
rcServer := newServer(opt, mux)
for _, test := range tests {
t.Run(test.Name, func(t *testing.T) {
@@ -536,7 +539,7 @@ func makeMetricsTestCases(stats *accounting.StatsInfo) (tests []testRun) {
return
}
var matchRemoteDirListing = regexp.MustCompile(`<title>List of all rclone remotes.</title>`)
var matchRemoteDirListing = regexp.MustCompile(`<title>Directory listing of /</title>`)
func TestServingRoot(t *testing.T) {
tests := []testRun{{