From fdecaffd0ff64d0346ef68ddb8a24c992631e5cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Geisendo=CC=88rfer?= Date: Wed, 8 May 2013 15:19:31 +0200 Subject: [PATCH] Add CORS support again --- src/cmd/tusd/main.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/cmd/tusd/main.go b/src/cmd/tusd/main.go index 61da14e..ae3ffd6 100644 --- a/src/cmd/tusd/main.go +++ b/src/cmd/tusd/main.go @@ -51,7 +51,20 @@ func main() { panic(err) } - http.Handle(basePath, tusHandler) + http.HandleFunc(basePath, func(w http.ResponseWriter, r *http.Request) { + // Allow CORS for almost everything. This needs to be revisted / limited to + // routes and methods that need it. + w.Header().Add("Access-Control-Allow-Origin", "*") + w.Header().Add("Access-Control-Allow-Methods", "HEAD,GET,PUT,POST,DELETE") + w.Header().Add("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Content-Range, Content-Disposition") + w.Header().Add("Access-Control-Expose-Headers", "Location, Range, Content-Disposition") + + if r.Method == "OPTIONS" { + return + } + + tusHandler.ServeHTTP(w, r) + }) go handleUploads(tusHandler)