Support data in initial PUT

This commit is contained in:
Felix Geisendörfer 2013-03-18 18:26:44 +01:00
parent 34d69e6937
commit 04184d26ed
2 changed files with 11 additions and 10 deletions

View File

@ -95,7 +95,6 @@ func getReceivedChunks(fileId string) (chunkSet, error) {
}
lines := strings.Split(string(data), "\n")
chunks := make(chunkSet, 0, len(lines)-1)
for i, line := range lines {
// last line is always empty, skip it
@ -105,17 +104,17 @@ func getReceivedChunks(fileId string) (chunkSet, error) {
parts := strings.Split(line, ",")
if len(parts) != 2 {
return nil, errors.New("getReceivedChunks: corrupt log line: "+line)
return nil, errors.New("getReceivedChunks: corrupt log line: " + line)
}
start, err := strconv.ParseInt(parts[0], 10, 64)
if err != nil {
return nil, errors.New("getReceivedChunks: invalid start: "+parts[0])
return nil, errors.New("getReceivedChunks: invalid start: " + parts[0])
}
end, err := strconv.ParseInt(parts[1], 10, 64)
if err != nil {
return nil, errors.New("getReceivedChunks: invalid end: "+parts[1])
return nil, errors.New("getReceivedChunks: invalid end: " + parts[1])
}
chunks.Add(chunk{Start: start, End: end})

View File

@ -61,11 +61,6 @@ func postFiles(w http.ResponseWriter, r *http.Request) {
return
}
if contentRange.End != -1 {
reply(w, http.StatusNotImplemented, "File data in initial request.")
return
}
contentType := r.Header.Get("Content-Type")
if contentType == "" {
contentType = "application/octet-stream"
@ -77,9 +72,16 @@ func postFiles(w http.ResponseWriter, r *http.Request) {
return
}
// @TODO: Return X-Missing header
if contentRange.End != -1 {
if err := putFileChunk(id, contentRange.Start, contentRange.End, r.Body); err != nil {
// @TODO: Could be a 404 as well
reply(w, http.StatusInternalServerError, err.Error())
return
}
}
w.Header().Set("Location", "/files/"+id)
setFileRangeHeader(w, id)
w.WriteHeader(http.StatusCreated)
}