Implement offset exceeded handling
This commit is contained in:
parent
ad47388d80
commit
56668dc701
|
@ -139,7 +139,18 @@ func (h *Handler) patchFile(w http.ResponseWriter, r *http.Request, id string) {
|
||||||
return
|
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
|
// @TODO Test offset < current offset
|
||||||
|
|
||||||
err = h.store.WriteFileChunk(id, offset, r.Body)
|
err = h.store.WriteFileChunk(id, offset, r.Body)
|
||||||
|
|
|
@ -177,7 +177,7 @@ var Protocol_Core_Tests = []struct {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Description: "Resume",
|
Description: "Simple Resume",
|
||||||
FinalLength: 11,
|
FinalLength: 11,
|
||||||
ExpectFileContent: "hello world",
|
ExpectFileContent: "hello world",
|
||||||
Requests: []TestRequest{
|
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) {
|
func TestProtocol_Core(t *testing.T) {
|
||||||
|
|
Loading…
Reference in New Issue