|
|
@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Minio Go Library for Amazon S3 Compatible Cloud Storage (C) 2016 Minio, Inc. |
|
|
|
* Minio Go Library for Amazon S3 Compatible Cloud Storage (C) 2016-17 Minio, Inc. |
|
|
|
* |
|
|
|
* |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
@ -83,23 +83,29 @@ func (c RequestHeaders) SetModified(modTime time.Time) error { |
|
|
|
// See https://tools.ietf.org/html/rfc7233#section-3.1 for reference.
|
|
|
|
// See https://tools.ietf.org/html/rfc7233#section-3.1 for reference.
|
|
|
|
func (c RequestHeaders) SetRange(start, end int64) error { |
|
|
|
func (c RequestHeaders) SetRange(start, end int64) error { |
|
|
|
switch { |
|
|
|
switch { |
|
|
|
case start <= 0 && end < 0: |
|
|
|
case start == 0 && end < 0: |
|
|
|
// Read everything until the 'end'. `bytes=-N`
|
|
|
|
// Read last '-end' bytes. `bytes=-N`.
|
|
|
|
c.Set("Range", fmt.Sprintf("bytes=%d", end)) |
|
|
|
c.Set("Range", fmt.Sprintf("bytes=%d", end)) |
|
|
|
case start > 0 && end == 0: |
|
|
|
case 0 < start && end == 0: |
|
|
|
// Read everything starting from offset 'start'. `bytes=N-`
|
|
|
|
// Read everything starting from offset
|
|
|
|
|
|
|
|
// 'start'. `bytes=N-`.
|
|
|
|
c.Set("Range", fmt.Sprintf("bytes=%d-", start)) |
|
|
|
c.Set("Range", fmt.Sprintf("bytes=%d-", start)) |
|
|
|
case start > 0 && end > 0 && end >= start: |
|
|
|
case 0 <= start && start <= end: |
|
|
|
// Read everything starting at 'start' till the 'end'. `bytes=N-M`
|
|
|
|
// Read everything starting at 'start' till the
|
|
|
|
|
|
|
|
// 'end'. `bytes=N-M`
|
|
|
|
c.Set("Range", fmt.Sprintf("bytes=%d-%d", start, end)) |
|
|
|
c.Set("Range", fmt.Sprintf("bytes=%d-%d", start, end)) |
|
|
|
case start == 0 && end == 0: |
|
|
|
default: |
|
|
|
// Client attempting to read the whole file.
|
|
|
|
|
|
|
|
return nil |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// All other cases such as
|
|
|
|
// All other cases such as
|
|
|
|
// bytes=-N-
|
|
|
|
// bytes=-3-
|
|
|
|
// bytes=N-M where M < N
|
|
|
|
// bytes=5-3
|
|
|
|
// These return error and are not supported.
|
|
|
|
// bytes=-2-4
|
|
|
|
return ErrInvalidArgument(fmt.Sprintf("Invalid range start and end specified bytes=%d-%d", |
|
|
|
// bytes=-3-0
|
|
|
|
|
|
|
|
// bytes=-3--2
|
|
|
|
|
|
|
|
// are invalid.
|
|
|
|
|
|
|
|
return ErrInvalidArgument( |
|
|
|
|
|
|
|
fmt.Sprintf( |
|
|
|
|
|
|
|
"Invalid range specified: start=%d end=%d", |
|
|
|
start, end)) |
|
|
|
start, end)) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return nil |
|
|
|
|
|
|
|
} |
|
|
|