Skip to content

Commit 74ba018

Browse files
committed
docs/fix tus#223 - added startup message about disabled downloads
chore/fix tus#333: - s3store - lowercase metadata keys, so client can send them in any case - fix possible errors for empty Basepath ("/") sec/fix tus#450 - allow accepting credentials (for example, Cookie, so forwarding in hooks will work as described in docs)
1 parent f78d41e commit 74ba018

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

cmd/tusd/cli/composer.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,11 @@ func CreateComposer() {
5858
}
5959

6060
if Flags.AllowCustomFilepath {
61-
stdout.Printf("Saving objects with custom path and filename enabled. Use CustomFilepath metadata.")
61+
stdout.Printf("Saving objects with custom path and filename enabled. Use CustomFilepath metadata.\n")
62+
}
63+
64+
if Flags.DisableDownload {
65+
stdout.Printf("Downloads disabled.\n")
6266
}
6367

6468
// Derive credentials from default credential chain (env, shared, ec2 instance role)

pkg/handler/unrouted_handler.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,12 @@ var (
2424
)
2525

2626
// Regexp tests: https://regex101.com/r/dEqVSE/1
27+
// TODO: cut off query part
2728
func getCustomFilepathIdRegexp(basepath string) *regexp.Regexp {
2829
basepath = strings.Replace(basepath, "/", "", -1)
30+
if basepath == "" {
31+
return regexp.MustCompile(`\/?(.+)\/$|\/?(.+)\/?$|([^\n\/]+)\/?$`)
32+
}
2933
return regexp.MustCompile(`\/?` + basepath + `\/(.+)\/$|\/?` + basepath + `\/(.+)\/?$|([^\/]+)\/?$`)
3034
}
3135

@@ -228,7 +232,8 @@ func (handler *UnroutedHandler) Middleware(h http.Handler) http.Handler {
228232
if r.Method == "OPTIONS" {
229233
// Preflight request
230234
header.Add("Access-Control-Allow-Methods", "POST, GET, HEAD, PATCH, DELETE, OPTIONS")
231-
header.Add("Access-Control-Allow-Headers", "Authorization, Origin, X-Requested-With, X-Request-ID, X-HTTP-Method-Override, Content-Type, Upload-Length, Upload-Offset, Tus-Resumable, Upload-Metadata, Upload-Defer-Length, Upload-Concat")
235+
// TODO: add headers from Flags.HttpHooksForwardHeaders and others
236+
header.Add("Access-Control-Allow-Headers", "Authorization, Cookie, Origin, X-Requested-With, X-Request-ID, X-HTTP-Method-Override, Content-Type, Upload-Length, Upload-Offset, Tus-Resumable, Upload-Metadata, Upload-Defer-Length, Upload-Concat")
232237
header.Set("Access-Control-Max-Age", "86400")
233238

234239
} else {
@@ -243,6 +248,9 @@ func (handler *UnroutedHandler) Middleware(h http.Handler) http.Handler {
243248
// Add nosniff to all responses https://golang.org/src/net/http/server.go#L1429
244249
header.Set("X-Content-Type-Options", "nosniff")
245250

251+
// https://github.com/tus/tusd/issues/450#issuecomment-765392832
252+
header.Set("Access-Control-Allow-Credentials", "true")
253+
246254
// Set appropriated headers in case of OPTIONS method allowing protocol
247255
// discovery and end with an 204 No Content
248256
if r.Method == "OPTIONS" {

pkg/s3store/s3store.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -226,12 +226,12 @@ func (store S3Store) NewUpload(ctx context.Context, info handler.FileInfo) (hand
226226
// Copying the value is required in order to prevent it from being
227227
// overwritten by the next iteration.
228228
v := nonPrintableRegexp.ReplaceAllString(value, "?")
229-
metadata[key] = &v
229+
metadata[strings.ToLower(key)] = &v
230230
}
231231

232232
var uploadId string
233233
if info.ID == "" {
234-
if filepath, keyExist := metadata["CustomFilepath"]; store.AllowCustomObjectPath && keyExist {
234+
if filepath, keyExist := metadata["customfilepath"]; store.AllowCustomObjectPath && keyExist {
235235
filepath := strings.Trim(*filepath, "/")
236236
if len(filepath) < 1 {
237237
return nil, fmt.Errorf("s3store: malformed CustomFilepath")

0 commit comments

Comments
 (0)