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 <marius@transloadit.com>
Date:   Mon Oct 18 00:27:12 2021 +0200

    Docs and test

commit 16d9dc67e8c8eefc328b1ce12d7e7ca01a49f9f6
Merge: bae0ffb bea5183
Author: Marius <marius@transloadit.com>
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 bea5183ec3
Author: Pavel Kirilin <win10@list.ru>
Date:   Thu May 20 19:53:36 2021 +0400

    Fixed "Tus-Resumable" header check for HEAD request.

    Signed-off-by: Pavel Kirilin <win10@list.ru>
This commit is contained in:
Marius 2021-10-18 00:29:13 +02:00
parent bae0ffb5e5
commit 84faa14987
2 changed files with 8 additions and 6 deletions

View File

@ -50,6 +50,7 @@ func TestHead(t *testing.T) {
ResHeader: map[string]string{ ResHeader: map[string]string{
"Upload-Offset": "11", "Upload-Offset": "11",
"Upload-Length": "44", "Upload-Length": "44",
"Content-Length": "44",
"Cache-Control": "no-store", "Cache-Control": "no-store",
}, },
}).Run(handler, t) }).Run(handler, t)

View File

@ -260,9 +260,9 @@ 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 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. This request is not part of the specification. // not include this header. GET requests are not part of the specification.
if r.Method != "GET" && r.Header.Get("Tus-Resumable") != "1.0.0" { if r.Method != "GET" && r.Method != "HEAD" && r.Header.Get("Tus-Resumable") != "1.0.0" {
handler.sendError(w, r, ErrUnsupportedVersion) handler.sendError(w, r, ErrUnsupportedVersion)
return return
} }
@ -472,6 +472,7 @@ func (handler *UnroutedHandler) HeadFile(w http.ResponseWriter, r *http.Request)
w.Header().Set("Upload-Defer-Length", UploadLengthDeferred) w.Header().Set("Upload-Defer-Length", UploadLengthDeferred)
} else { } else {
w.Header().Set("Upload-Length", strconv.FormatInt(info.Size, 10)) 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") w.Header().Set("Cache-Control", "no-store")