From 83d367fd115aaedc5998e2553dcf0ce5354a2d15 Mon Sep 17 00:00:00 2001 From: tim-kos Date: Tue, 19 Mar 2013 16:36:48 +0100 Subject: [PATCH] add more headers, routes and also allow POSTING to /files/ to add compatibility with jQuery File Upload --- src/cmd/tusd/http.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/cmd/tusd/http.go b/src/cmd/tusd/http.go index 37ae865..19e0eae 100644 --- a/src/cmd/tusd/http.go +++ b/src/cmd/tusd/http.go @@ -12,6 +12,7 @@ import ( ) var fileRoute = regexp.MustCompile("^/files/([^/]+)$") +var filesRoute = regexp.MustCompile("^/files/?$") var dataStore *DataStore func init() { @@ -41,11 +42,16 @@ func route(w http.ResponseWriter, r *http.Request) { w.Header().Set("Server", "tusd") w.Header().Add("Access-Control-Allow-Origin", "*") + 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") - if r.Method == "POST" && r.URL.Path == "/files" { + if r.Method == "OPTIONS" { + reply(w, http.StatusOK, "") + return + } + + if r.Method == "POST" && filesRoute.Match([]byte(r.URL.Path)) { postFiles(w, r) - } else if r.Method == "OPTIONS" && r.URL.Path == "/files" { - reply(w, http.StatusOK, "Cool") } else if match := fileRoute.FindStringSubmatch(r.URL.Path); match != nil { id := match[1] switch r.Method { @@ -53,6 +59,8 @@ func route(w http.ResponseWriter, r *http.Request) { headFile(w, r, id) case "GET": getFile(w, r, id) + case "POST": + putFile(w, r, id) case "PUT": putFile(w, r, id) default: