From 141a49a38de7317b1aace9f051acb4a8ce9a5910 Mon Sep 17 00:00:00 2001 From: Marius Date: Mon, 19 Aug 2019 12:03:14 +0200 Subject: [PATCH] cli: Allow uploads without trailing slash --- cmd/tusd/cli/serve.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cmd/tusd/cli/serve.go b/cmd/tusd/cli/serve.go index c4525ef..522ccb9 100644 --- a/cmd/tusd/cli/serve.go +++ b/cmd/tusd/cli/serve.go @@ -3,6 +3,7 @@ package cli import ( "net" "net/http" + "strings" "time" "github.com/tus/tusd/pkg/handler" @@ -63,6 +64,13 @@ func Serve() { http.Handle(basepath, http.StripPrefix(basepath, handler)) + // Also register a route without the trailing slash, so we can handle uploads + // for /files/ and /files, for example. + if strings.HasSuffix(basepath, "/") { + basepathWithoutSlash := strings.TrimSuffix(basepath, "/") + http.Handle(basepathWithoutSlash, http.StripPrefix(basepathWithoutSlash, handler)) + } + var listener net.Listener timeoutDuration := time.Duration(Flags.Timeout) * time.Millisecond