@ -17,6 +17,7 @@
package minioapi
package minioapi
import (
import (
"errors"
"fmt"
"fmt"
"strconv"
"strconv"
"strings"
"strings"
@ -58,28 +59,28 @@ func newRange(req *http.Request, size int64) (*httpRange, error) {
// parseRange parses a Range header string as per RFC 2616.
// parseRange parses a Range header string as per RFC 2616.
func ( r * httpRange ) parseRange ( s string ) error {
func ( r * httpRange ) parseRange ( s string ) error {
if s == "" {
if s == "" {
return fmt . Errorf ( "header not present" )
return errors . New ( "header not present" )
}
}
if ! strings . HasPrefix ( s , b ) {
if ! strings . HasPrefix ( s , b ) {
return fmt . Errorf ( "invalid range" )
return errors . New ( "invalid range" )
}
}
ras := strings . Split ( s [ len ( b ) : ] , "," )
ras := strings . Split ( s [ len ( b ) : ] , "," )
if len ( ras ) == 0 {
if len ( ras ) == 0 {
return fmt . Errorf ( "invalid request" )
return errors . New ( "invalid request" )
}
}
// Just pick the first one and ignore the rest, we only support one range per object
// Just pick the first one and ignore the rest, we only support one range per object
if len ( ras ) > 1 {
if len ( ras ) > 1 {
return fmt . Errorf ( "multiple ranges specified" )
return errors . New ( "multiple ranges specified" )
}
}
ra := strings . TrimSpace ( ras [ 0 ] )
ra := strings . TrimSpace ( ras [ 0 ] )
if ra == "" {
if ra == "" {
return fmt . Errorf ( "invalid range" )
return errors . New ( "invalid range" )
}
}
i := strings . Index ( ra , "-" )
i := strings . Index ( ra , "-" )
if i < 0 {
if i < 0 {
return fmt . Errorf ( "invalid range" )
return errors . New ( "invalid range" )
}
}
start , end := strings . TrimSpace ( ra [ : i ] ) , strings . TrimSpace ( ra [ i + 1 : ] )
start , end := strings . TrimSpace ( ra [ : i ] ) , strings . TrimSpace ( ra [ i + 1 : ] )
if start == "" {
if start == "" {
@ -87,7 +88,7 @@ func (r *httpRange) parseRange(s string) error {
// range start relative to the end of the file.
// range start relative to the end of the file.
i , err := strconv . ParseInt ( end , 10 , 64 )
i , err := strconv . ParseInt ( end , 10 , 64 )
if err != nil {
if err != nil {
return fmt . Errorf ( "invalid range" )
return errors . New ( "invalid range" )
}
}
if i > r . size {
if i > r . size {
i = r . size
i = r . size
@ -97,7 +98,7 @@ func (r *httpRange) parseRange(s string) error {
} else {
} else {
i , err := strconv . ParseInt ( start , 10 , 64 )
i , err := strconv . ParseInt ( start , 10 , 64 )
if err != nil || i > r . size || i < 0 {
if err != nil || i > r . size || i < 0 {
return fmt . Errorf ( "invalid range" )
return errors . New ( "invalid range" )
}
}
r . start = i
r . start = i
if end == "" {
if end == "" {
@ -106,7 +107,7 @@ func (r *httpRange) parseRange(s string) error {
} else {
} else {
i , err := strconv . ParseInt ( end , 10 , 64 )
i , err := strconv . ParseInt ( end , 10 , 64 )
if err != nil || r . start > i {
if err != nil || r . start > i {
return fmt . Errorf ( "invalid range" )
return errors . New ( "invalid range" )
}
}
if i >= r . size {
if i >= r . size {
i = r . size - 1
i = r . size - 1