cli: Allow uploads without trailing slash

This commit is contained in:
Marius 2019-08-19 12:03:14 +02:00
parent bfac68d84c
commit 141a49a38d
1 changed files with 8 additions and 0 deletions

View File

@ -3,6 +3,7 @@ package cli
import ( import (
"net" "net"
"net/http" "net/http"
"strings"
"time" "time"
"github.com/tus/tusd/pkg/handler" "github.com/tus/tusd/pkg/handler"
@ -63,6 +64,13 @@ func Serve() {
http.Handle(basepath, http.StripPrefix(basepath, handler)) 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 var listener net.Listener
timeoutDuration := time.Duration(Flags.Timeout) * time.Millisecond timeoutDuration := time.Duration(Flags.Timeout) * time.Millisecond