Add flag to enable support for tus v2

This commit is contained in:
Marius 2021-11-15 13:38:48 +01:00
parent 9c9cfc534e
commit c941e5ef9a
4 changed files with 7 additions and 1 deletions

View File

@ -56,6 +56,7 @@ var Flags struct {
TLSCertFile string TLSCertFile string
TLSKeyFile string TLSKeyFile string
TLSMode string TLSMode string
TusV2 bool
CPUProfile string 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.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.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.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.StringVar(&Flags.CPUProfile, "cpuprofile", "", "write cpu profile to file")
flag.Parse() flag.Parse()

View File

@ -27,6 +27,7 @@ func Serve() {
MaxSize: Flags.MaxSize, MaxSize: Flags.MaxSize,
BasePath: Flags.Basepath, BasePath: Flags.Basepath,
RespectForwardedHeaders: Flags.BehindProxy, RespectForwardedHeaders: Flags.BehindProxy,
EnableTusV2: Flags.TusV2,
StoreComposer: Composer, StoreComposer: Composer,
NotifyCompleteUploads: true, NotifyCompleteUploads: true,
NotifyTerminatedUploads: true, NotifyTerminatedUploads: true,

View File

@ -22,6 +22,9 @@ type Config struct {
// absolute URL containing a scheme, e.g. "http://tus.io" // absolute URL containing a scheme, e.g. "http://tus.io"
BasePath string BasePath string
isAbs bool 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 // NotifyCompleteUploads indicates whether sending notifications about
// completed uploads using the CompleteUploads channel should be enabled. // completed uploads using the CompleteUploads channel should be enabled.
NotifyCompleteUploads bool NotifyCompleteUploads bool

View File

@ -262,7 +262,7 @@ func (handler *UnroutedHandler) Middleware(h http.Handler) http.Handler {
// Test if the version sent by the client is supported // 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 // 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. // 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) handler.sendError(w, r, ErrUnsupportedVersion)
return return
} }