Skip to content

Commit

Permalink
Fixing content length when user requests more than the length to the …
Browse files Browse the repository at this point in the history
…end of the file.
  • Loading branch information
jaredbischof committed Jul 27, 2015
1 parent e446e35 commit 24a4dcf
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions shock-server/controller/node/single.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ func (cr *NodeController) Read(id string, ctx context.Context) error {
if err != nil {
return responder.RespondWithError(ctx, http.StatusBadRequest, "length must be an integer value")
}
if length > n.File.Size {
length = n.File.Size
}
} else if !length_ok {
seek_str := query.Get("seek")
seek, err = strconv.ParseInt(seek_str, 10, 0)
Expand All @@ -132,6 +135,9 @@ func (cr *NodeController) Read(id string, ctx context.Context) error {
if err != nil {
return responder.RespondWithError(ctx, http.StatusBadRequest, "length must be an integer value")
}
if length > n.File.Size-seek {
length = n.File.Size - seek
}
}
r, err := n.FileReader()
defer r.Close()
Expand Down

0 comments on commit 24a4dcf

Please sign in to comment.