"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files
Go azure-blobazure-blob-storageazure-filesbackblaze-b2cloud-storagedropboxencryptionftpfuse-filesystemgogolanggoogle-cloud-storagegoogle-driveonedriveopenstack-swiftrclones3sftpsyncwebdav
http: clean up Bind to better use middleware
Nolan Woodsab7dfe0c874e
diff --git a/cmd/serve/http/http.go b/cmd/serve/http/http.goindex ca4a071ca..dab1489d7 100644--- a/cmd/serve/http/http.go+++ b/cmd/serve/http/http.go@@ -12,6 +12,7 @@ import ("time""github.com/go-chi/chi/v5"+ "github.com/go-chi/chi/v5/middleware""github.com/rclone/rclone/cmd""github.com/rclone/rclone/cmd/serve/http/data""github.com/rclone/rclone/fs"@@ -67,7 +68,7 @@ control the stats printing.if err != nil {return err}- s.Bind("/*", router)+ s.Bind(router)return nil})},@@ -93,18 +94,17 @@ func newServer(f fs.Fs, templatePath string) *server {return s}-func (s *server) Bind(pattern string, router chi.Router) {- router.Get(pattern, s.handler)- router.Head(pattern, s.handler)+func (s *server) Bind(router chi.Router) {+ router.Use(+ middleware.SetHeader("Accept-Ranges", "bytes"),+ middleware.SetHeader("Server", "rclone/"+fs.Version),+ )+ router.Get("/*", s.handler)+ router.Head("/*", s.handler)}// handler reads incoming requests and dispatches themfunc (s *server) handler(w http.ResponseWriter, r *http.Request) {- w.Header().Set("Accept-Ranges", "bytes")- w.Header().Set("Server", "rclone/"+fs.Version)-- //rctx := chi.RouteContext(r.Context())-isDir := strings.HasSuffix(r.URL.Path, "/")remote := strings.Trim(r.URL.Path, "/")if isDir {diff --git a/cmd/serve/http/http_test.go b/cmd/serve/http/http_test.goindex 311bac70b..148b5d22a 100644--- a/cmd/serve/http/http_test.go+++ b/cmd/serve/http/http_test.go@@ -37,7 +37,7 @@ func startServer(t *testing.T, f fs.Fs) {if err != nil {t.Fatal(err.Error())}- httpServer.Bind("/*", router)+ httpServer.Bind(router)testURL = httplib.URL()// try to connect to the test server