add support for POST requests that do not provide a content-range header

This commit is contained in:
tim-kos 2013-03-19 16:55:35 +01:00
parent 83d367fd11
commit 529614515a
1 changed files with 21 additions and 4 deletions

View File

@ -137,16 +137,33 @@ func getFile(w http.ResponseWriter, r *http.Request, fileId string) {
} }
func putFile(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")) contentRange, err := parseContentRange(r.Header.Get("Content-Range"))
if err != nil { if err != nil {
reply(w, http.StatusBadRequest, err.Error()) contentLength := r.Header.Get("Content-Length")
return 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: 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 // @TODO: Could be a 404 as well
reply(w, http.StatusInternalServerError, err.Error()) reply(w, http.StatusInternalServerError, err.Error())
return return