From c941e5ef9a99427a09f3a81395f4cd17b32bb1a1 Mon Sep 17 00:00:00 2001 From: Marius Date: Mon, 15 Nov 2021 13:38:48 +0100 Subject: [PATCH] Add flag to enable support for tus v2 --- cmd/tusd/cli/flags.go | 2 ++ cmd/tusd/cli/serve.go | 1 + pkg/handler/config.go | 3 +++ pkg/handler/unrouted_handler.go | 2 +- 4 files changed, 7 insertions(+), 1 deletion(-) diff --git a/cmd/tusd/cli/flags.go b/cmd/tusd/cli/flags.go index 1e1a647..8e2441c 100644 --- a/cmd/tusd/cli/flags.go +++ b/cmd/tusd/cli/flags.go @@ -56,6 +56,7 @@ var Flags struct { TLSCertFile string TLSKeyFile string TLSMode string + TusV2 bool CPUProfile string } @@ -102,6 +103,7 @@ func ParseFlags() { flag.StringVar(&Flags.TLSCertFile, "tls-certificate", "", "Path to the file containing the x509 TLS certificate to be used. The file should also contain any intermediate certificates and the CA certificate.") flag.StringVar(&Flags.TLSKeyFile, "tls-key", "", "Path to the file containing the key for the TLS certificate.") flag.StringVar(&Flags.TLSMode, "tls-mode", "tls12", "Specify which TLS mode to use; valid modes are tls13, tls12, and tls12-strong.") + flag.BoolVar(&Flags.TusV2, "enable-tus-v2", false, "Enable support for the tus v2 protocol, next to support for v1 (experimental and may be removed/changed in the future)") flag.StringVar(&Flags.CPUProfile, "cpuprofile", "", "write cpu profile to file") flag.Parse() diff --git a/cmd/tusd/cli/serve.go b/cmd/tusd/cli/serve.go index 3cbd718..9170530 100644 --- a/cmd/tusd/cli/serve.go +++ b/cmd/tusd/cli/serve.go @@ -27,6 +27,7 @@ func Serve() { MaxSize: Flags.MaxSize, BasePath: Flags.Basepath, RespectForwardedHeaders: Flags.BehindProxy, + EnableTusV2: Flags.TusV2, StoreComposer: Composer, NotifyCompleteUploads: true, NotifyTerminatedUploads: true, diff --git a/pkg/handler/config.go b/pkg/handler/config.go index ae9676b..75fbada 100644 --- a/pkg/handler/config.go +++ b/pkg/handler/config.go @@ -22,6 +22,9 @@ type Config struct { // absolute URL containing a scheme, e.g. "http://tus.io" BasePath string isAbs bool + // EnableTusV2 controls whether the new and experimental tus v2 protocol is + // accepted, next to the current tus v1 protocol. + EnableTusV2 bool // NotifyCompleteUploads indicates whether sending notifications about // completed uploads using the CompleteUploads channel should be enabled. NotifyCompleteUploads bool diff --git a/pkg/handler/unrouted_handler.go b/pkg/handler/unrouted_handler.go index 6c5f52b..718d405 100644 --- a/pkg/handler/unrouted_handler.go +++ b/pkg/handler/unrouted_handler.go @@ -262,7 +262,7 @@ func (handler *UnroutedHandler) Middleware(h http.Handler) http.Handler { // Test if the version sent by the client is supported // GET and HEAD methods are not checked since a browser may visit this URL and does // not include this header. GET requests are not part of the specification. - if r.Method != "GET" && r.Method != "HEAD" && r.Header.Get("Tus-Resumable") != "1.0.0" { + if r.Method != "GET" && r.Method != "HEAD" && r.Header.Get("Tus-Resumable") != "1.0.0" && !handler.config.EnableTusV2 { handler.sendError(w, r, ErrUnsupportedVersion) return }