Preserve Delamain stale slice error responses
This commit is contained in:
1 parent
48c7ab4618
commit
527255f5b7
1 file changed
+6
-2
@@ -86,18 +86,22 @@ func (g *apiGuard) readSlice(w http.ResponseWriter, r *http.Request) {
|
||||
writeError(w, http.StatusUnauthorized, "authentication required")
|
||||
return
|
||||
}
|
||||
if request.Slot >= 32 {
|
||||
writeJSON(w, http.StatusOK, map[string]any{"status": -1, "error": "invalid-slot"})
|
||||
return
|
||||
}
|
||||
g.notesMu.Lock()
|
||||
note, found := g.notes[request.noteHandle]
|
||||
g.notesMu.Unlock()
|
||||
if !found || time.Since(note.created) >= noteLifetime {
|
||||
writeError(w, http.StatusForbidden, "note unavailable")
|
||||
writeJSON(w, http.StatusOK, map[string]any{"status": -2, "error": "stale-generation"})
|
||||
return
|
||||
}
|
||||
if !g.requireTripOwner(w, r, note.tripID) {
|
||||
return
|
||||
}
|
||||
size := uint64(len(note.data))
|
||||
if request.Offset > size || request.Length > size-request.Offset {
|
||||
if request.Length == 0 || request.Offset >= size || request.Length > size-request.Offset {
|
||||
writeJSON(w, http.StatusOK, map[string]any{"status": -4, "error": "out-of-bounds"})
|
||||
return
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user