From 84faa14987da8c5bd9da9ed2cad16fe1b7941bbb Mon Sep 17 00:00:00 2001 From: Marius Date: Mon, 18 Oct 2021 00:29:13 +0200 Subject: [PATCH] core: Allow non-tus HEAD requests, Add Length to HEAD responses See https://github.com/tus/tusd/pull/480 Squashed commit of the following: commit 7439fd84a6103afdedaf94701a65ce4376789380 Author: Marius Date: Mon Oct 18 00:27:12 2021 +0200 Docs and test commit 16d9dc67e8c8eefc328b1ce12d7e7ca01a49f9f6 Merge: bae0ffb bea5183 Author: Marius Date: Mon Oct 18 00:23:13 2021 +0200 Merge branch 'head_header_check' of https://github.com/s3rius/tusd into s3rius-head_header_check commit bea5183ec3f8759efadb554b5dd1acd18187d055 Author: Pavel Kirilin Date: Thu May 20 19:53:36 2021 +0400 Fixed "Tus-Resumable" header check for HEAD request. Signed-off-by: Pavel Kirilin --- pkg/handler/head_test.go | 7 ++++--- pkg/handler/unrouted_handler.go | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/pkg/handler/head_test.go b/pkg/handler/head_test.go index 59da085..b5c83bb 100644 --- a/pkg/handler/head_test.go +++ b/pkg/handler/head_test.go @@ -48,9 +48,10 @@ func TestHead(t *testing.T) { }, Code: http.StatusOK, ResHeader: map[string]string{ - "Upload-Offset": "11", - "Upload-Length": "44", - "Cache-Control": "no-store", + "Upload-Offset": "11", + "Upload-Length": "44", + "Content-Length": "44", + "Cache-Control": "no-store", }, }).Run(handler, t) diff --git a/pkg/handler/unrouted_handler.go b/pkg/handler/unrouted_handler.go index ba2fb42..6c5f52b 100644 --- a/pkg/handler/unrouted_handler.go +++ b/pkg/handler/unrouted_handler.go @@ -260,9 +260,9 @@ func (handler *UnroutedHandler) Middleware(h http.Handler) http.Handler { } // Test if the version sent by the client is supported - // GET methods are not checked since a browser may visit this URL and does - // not include this header. This request is not part of the specification. - if r.Method != "GET" && r.Header.Get("Tus-Resumable") != "1.0.0" { + // 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" { handler.sendError(w, r, ErrUnsupportedVersion) return } @@ -472,6 +472,7 @@ func (handler *UnroutedHandler) HeadFile(w http.ResponseWriter, r *http.Request) w.Header().Set("Upload-Defer-Length", UploadLengthDeferred) } else { w.Header().Set("Upload-Length", strconv.FormatInt(info.Size, 10)) + w.Header().Set("Content-Length", strconv.FormatInt(info.Size, 10)) } w.Header().Set("Cache-Control", "no-store")