Implement offset exceeded handling

This commit is contained in:
Felix Geisendörfer 2013-05-08 15:59:42 +02:00
parent ad47388d80
commit 56668dc701
2 changed files with 27 additions and 3 deletions

View File

@ -139,7 +139,18 @@ func (h *Handler) patchFile(w http.ResponseWriter, r *http.Request, id string) {
return
}
// @TODO Reject if offset > current offset
info, err := h.store.GetInfo(id)
if err != nil {
h.err(err, w, http.StatusInternalServerError)
return
}
if offset > info.Offset {
err = fmt.Errorf("Offset: %d exceeds current offset: %d", offset, info.Offset)
h.err(err, w, http.StatusForbidden)
return
}
// @TODO Test offset < current offset
err = h.store.WriteFileChunk(id, offset, r.Body)

View File

@ -177,7 +177,7 @@ var Protocol_Core_Tests = []struct {
},
},
{
Description: "Resume",
Description: "Simple Resume",
FinalLength: 11,
ExpectFileContent: "hello world",
Requests: []TestRequest{
@ -200,7 +200,20 @@ var Protocol_Core_Tests = []struct {
},
},
},
// @TODO Test applying PATCH at offset > current offset (error)
{
Description: "Offset exceeded",
FinalLength: 5,
Requests: []TestRequest{
{
Method: "PATCH",
Headers: map[string]string{"Offset": "1"},
// Not sure if this is the right status to use. Once the parallel
// chunks protocol spec is done, we can use NotImplemented as a
// status until we implement support for this.
ExpectStatusCode: http.StatusForbidden,
},
},
},
}
func TestProtocol_Core(t *testing.T) {