Do not pass chunk for uploaded uploads to data store
This commit is contained in:
parent
199487bdf6
commit
4e8842d91c
|
@ -286,3 +286,41 @@ func TestLockingPatch(t *testing.T) {
|
||||||
t.Error("expected no more calls to happen")
|
t.Error("expected no more calls to happen")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type finishedPatchStore struct {
|
||||||
|
zeroStore
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s finishedPatchStore) GetInfo(id string) (FileInfo, error) {
|
||||||
|
return FileInfo{
|
||||||
|
Offset: 20,
|
||||||
|
Size: 20,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s finishedPatchStore) WriteChunk(id string, offset int64, src io.Reader) (int64, error) {
|
||||||
|
panic("WriteChunk must not be called")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFinishedPatch(t *testing.T) {
|
||||||
|
|
||||||
|
handler, _ := NewHandler(Config{
|
||||||
|
DataStore: finishedPatchStore{},
|
||||||
|
})
|
||||||
|
|
||||||
|
(&httpTest{
|
||||||
|
Name: "Uploading to finished upload",
|
||||||
|
Method: "PATCH",
|
||||||
|
URL: "yes",
|
||||||
|
ReqHeader: map[string]string{
|
||||||
|
"Tus-Resumable": "1.0.0",
|
||||||
|
"Content-Type": "application/offset+octet-stream",
|
||||||
|
"Upload-Offset": "20",
|
||||||
|
},
|
||||||
|
ReqBody: strings.NewReader(""),
|
||||||
|
Code: http.StatusNoContent,
|
||||||
|
ResHeader: map[string]string{
|
||||||
|
"Upload-Offset": "20",
|
||||||
|
},
|
||||||
|
}).Run(handler, t)
|
||||||
|
}
|
||||||
|
|
|
@ -348,6 +348,13 @@ func (handler *UnroutedHandler) PatchFile(w http.ResponseWriter, r *http.Request
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Do not proxy the call to the data store if the upload is already completed
|
||||||
|
if info.Offset == info.Size {
|
||||||
|
w.Header().Set("Upload-Offset", strconv.FormatInt(offset, 10))
|
||||||
|
w.WriteHeader(http.StatusNoContent)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Get Content-Length if possible
|
// Get Content-Length if possible
|
||||||
length := r.ContentLength
|
length := r.ContentLength
|
||||||
|
|
||||||
|
@ -362,7 +369,7 @@ func (handler *UnroutedHandler) PatchFile(w http.ResponseWriter, r *http.Request
|
||||||
maxSize = length
|
maxSize = length
|
||||||
}
|
}
|
||||||
|
|
||||||
// Limit the
|
// Limit the data read from the request's body to the allowed maxiumum
|
||||||
reader := io.LimitReader(r.Body, maxSize)
|
reader := io.LimitReader(r.Body, maxSize)
|
||||||
|
|
||||||
bytesWritten, err := handler.composer.Core.WriteChunk(id, offset, reader)
|
bytesWritten, err := handler.composer.Core.WriteChunk(id, offset, reader)
|
||||||
|
|
Loading…
Reference in New Issue