From 529614515abb0aa923495961858d11a093f03429 Mon Sep 17 00:00:00 2001 From: tim-kos Date: Tue, 19 Mar 2013 16:55:35 +0100 Subject: [PATCH] add support for POST requests that do not provide a content-range header --- src/cmd/tusd/http.go | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/cmd/tusd/http.go b/src/cmd/tusd/http.go index 19e0eae..a4431c2 100644 --- a/src/cmd/tusd/http.go +++ b/src/cmd/tusd/http.go @@ -137,16 +137,33 @@ func getFile(w http.ResponseWriter, r *http.Request, fileId string) { } func putFile(w http.ResponseWriter, r *http.Request, fileId string) { + var start int64 = 0 + var end int64 = 0 + contentRange, err := parseContentRange(r.Header.Get("Content-Range")) if err != nil { - reply(w, http.StatusBadRequest, err.Error()) - return + contentLength := r.Header.Get("Content-Length") + end, err = strconv.ParseInt(contentLength, 10, 64) + if err != nil { + reply(w, http.StatusBadRequest, "Invalid content length provided") + } + + // we are zero-indexed + end = end - 1 + + // @TODO: Make sure contentLength matches the content length of the initial + // POST request + } else { + + // @TODO: Make sure contentRange.Size matches file size + + start = contentRange.Start + end = contentRange.End } // @TODO: Check that file exists - // @TODO: Make sure contentRange.Size matches file size - if err := dataStore.WriteFileChunk(fileId, contentRange.Start, contentRange.End, r.Body); err != nil { + if err := dataStore.WriteFileChunk(fileId, start, end, r.Body); err != nil { // @TODO: Could be a 404 as well reply(w, http.StatusInternalServerError, err.Error()) return