mirror of
https://github.com/rclone/rclone.git
synced 2025-08-19 01:46:31 +02:00
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:
@@ -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{{
|
||||
|
Reference in New Issue
Block a user